mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-24 22:38:27 +08:00
clean up merge of bren2010's crypto branch and merge into master
This commit is contained in:
@ -18,7 +18,7 @@ func TestFileConsistency(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, err := dag.NewDagReader(nd)
|
r, err := dag.NewDagReader(nd, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ func TestFileConsistencyLargeBlocks(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, err := dag.NewDagReader(nd)
|
r, err := dag.NewDagReader(nd, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,10 @@ func (dht *IpfsDHT) peerFromInfo(pbp *PBDHTMessage_PBPeer) (*peer.Peer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dht *IpfsDHT) loadProvidableKeys() error {
|
func (dht *IpfsDHT) loadProvidableKeys() error {
|
||||||
kl := dht.datastore.KeyList()
|
kl, err := dht.datastore.KeyList()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for _, k := range kl {
|
for _, k := range kl {
|
||||||
dht.providers.AddProvider(u.Key(k.Bytes()), dht.self)
|
dht.providers.AddProvider(u.Key(k.Bytes()), dht.self)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func setupDHTS(n int, t *testing.T) ([]*ma.Multiaddr, []*peer.Peer, []*IpfsDHT)
|
|||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
p := new(peer.Peer)
|
p := new(peer.Peer)
|
||||||
p.AddAddress(addrs[i])
|
p.AddAddress(addrs[i])
|
||||||
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 256)
|
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ func setupDHTS(n int, t *testing.T) ([]*ma.Multiaddr, []*peer.Peer, []*IpfsDHT)
|
|||||||
func makePeer(addr *ma.Multiaddr) *peer.Peer {
|
func makePeer(addr *ma.Multiaddr) *peer.Peer {
|
||||||
p := new(peer.Peer)
|
p := new(peer.Peer)
|
||||||
p.AddAddress(addr)
|
p.AddAddress(addr)
|
||||||
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 256)
|
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,6 @@ func TestNotFound(t *testing.T) {
|
|||||||
|
|
||||||
// Reply with random peers to every message
|
// Reply with random peers to every message
|
||||||
fn.AddHandler(func(mes *swarm.Message) *swarm.Message {
|
fn.AddHandler(func(mes *swarm.Message) *swarm.Message {
|
||||||
t.Log("Handling message...")
|
|
||||||
pmes := new(PBDHTMessage)
|
pmes := new(PBDHTMessage)
|
||||||
err := proto.Unmarshal(mes.Data, pmes)
|
err := proto.Unmarshal(mes.Data, pmes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -252,7 +251,6 @@ func TestLessThanKResponses(t *testing.T) {
|
|||||||
|
|
||||||
// Reply with random peers to every message
|
// Reply with random peers to every message
|
||||||
fn.AddHandler(func(mes *swarm.Message) *swarm.Message {
|
fn.AddHandler(func(mes *swarm.Message) *swarm.Message {
|
||||||
t.Log("Handling message...")
|
|
||||||
pmes := new(PBDHTMessage)
|
pmes := new(PBDHTMessage)
|
||||||
err := proto.Unmarshal(mes.Data, pmes)
|
err := proto.Unmarshal(mes.Data, pmes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -25,6 +25,8 @@ type Conn struct {
|
|||||||
Closed chan bool
|
Closed chan bool
|
||||||
Outgoing *msgio.Chan
|
Outgoing *msgio.Chan
|
||||||
Incoming *msgio.Chan
|
Incoming *msgio.Chan
|
||||||
|
secIn chan []byte
|
||||||
|
secOut chan []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnMap maps Keys (Peer.IDs) to Connections.
|
// ConnMap maps Keys (Peer.IDs) to Connections.
|
||||||
|
@ -172,7 +172,7 @@ func (s *Swarm) handleNewConn(nconn net.Conn) {
|
|||||||
}
|
}
|
||||||
newConnChans(conn)
|
newConnChans(conn)
|
||||||
|
|
||||||
_, _, err := ident.Handshake(s.local, p, conn.Incoming.MsgChan, conn.Outgoing.MsgChan)
|
sin, sout, err := ident.Handshake(s.local, p, conn.Incoming.MsgChan, conn.Outgoing.MsgChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.PErr("%v\n", err.Error())
|
u.PErr("%v\n", err.Error())
|
||||||
conn.Close()
|
conn.Close()
|
||||||
@ -180,7 +180,7 @@ func (s *Swarm) handleNewConn(nconn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get address to contact remote peer from
|
// Get address to contact remote peer from
|
||||||
addr := <-conn.Incoming.MsgChan
|
addr := <-sin
|
||||||
maddr, err := ma.NewMultiaddr(string(addr))
|
maddr, err := ma.NewMultiaddr(string(addr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.PErr("Got invalid address from peer.")
|
u.PErr("Got invalid address from peer.")
|
||||||
@ -189,6 +189,9 @@ func (s *Swarm) handleNewConn(nconn net.Conn) {
|
|||||||
}
|
}
|
||||||
p.AddAddress(maddr)
|
p.AddAddress(maddr)
|
||||||
|
|
||||||
|
conn.secIn = sin
|
||||||
|
conn.secOut = sout
|
||||||
|
|
||||||
err = s.StartConn(conn)
|
err = s.StartConn(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Error(err)
|
s.Error(err)
|
||||||
@ -295,7 +298,7 @@ func (s *Swarm) fanOut() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// queue it in the connection's buffer
|
// queue it in the connection's buffer
|
||||||
conn.Outgoing.MsgChan <- msg.Data
|
conn.secOut <- msg.Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,7 +316,7 @@ func (s *Swarm) fanIn(conn *Conn) {
|
|||||||
case <-conn.Closed:
|
case <-conn.Closed:
|
||||||
goto out
|
goto out
|
||||||
|
|
||||||
case data, ok := <-conn.Incoming.MsgChan:
|
case data, ok := <-conn.secIn:
|
||||||
if !ok {
|
if !ok {
|
||||||
e := fmt.Errorf("Error retrieving from conn: %v", conn.Peer.Key().Pretty())
|
e := fmt.Errorf("Error retrieving from conn: %v", conn.Peer.Key().Pretty())
|
||||||
s.Chan.Errors <- e
|
s.Chan.Errors <- e
|
||||||
@ -424,7 +427,7 @@ func (s *Swarm) GetConnection(id peer.ID, addr *ma.Multiaddr) (*peer.Peer, error
|
|||||||
|
|
||||||
// Handle performing a handshake on a new connection and ensuring proper forward communication
|
// Handle performing a handshake on a new connection and ensuring proper forward communication
|
||||||
func (s *Swarm) handleDialedCon(conn *Conn) error {
|
func (s *Swarm) handleDialedCon(conn *Conn) error {
|
||||||
_, _, err := ident.Handshake(s.local, conn.Peer, conn.Incoming.MsgChan, conn.Outgoing.MsgChan)
|
sin, sout, err := ident.Handshake(s.local, conn.Peer, conn.Incoming.MsgChan, conn.Outgoing.MsgChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -433,10 +436,13 @@ func (s *Swarm) handleDialedCon(conn *Conn) error {
|
|||||||
myaddr := s.local.NetAddress("tcp")
|
myaddr := s.local.NetAddress("tcp")
|
||||||
mastr, err := myaddr.String()
|
mastr, err := myaddr.String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.New("No local address to send to peer.")
|
return errors.New("No local address to send to peer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.Outgoing.MsgChan <- []byte(mastr)
|
sout <- []byte(mastr)
|
||||||
|
|
||||||
|
conn.secIn = sin
|
||||||
|
conn.secOut = sout
|
||||||
|
|
||||||
s.StartConn(conn)
|
s.StartConn(conn)
|
||||||
|
|
||||||
|
@ -89,6 +89,10 @@ func TestSwarm(t *testing.T) {
|
|||||||
t.Fatal("error swarm dialing to peer", err)
|
t.Fatal("error swarm dialing to peer", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Since we arent doing a handshake, set up 'secure' channels
|
||||||
|
conn.secIn = conn.Incoming.MsgChan
|
||||||
|
conn.secOut = conn.Outgoing.MsgChan
|
||||||
|
|
||||||
swarm.StartConn(conn)
|
swarm.StartConn(conn)
|
||||||
// ok done, add it.
|
// ok done, add it.
|
||||||
peers = append(peers, peer)
|
peers = append(peers, peer)
|
||||||
|
Reference in New Issue
Block a user