Commit 1fa7c07d authored by Jeromy's avatar Jeromy

clean up merge of bren2010's crypto branch and merge into master

parent f19e2201
......@@ -18,7 +18,7 @@ func TestFileConsistency(t *testing.T) {
if err != nil {
t.Fatal(err)
}
r, err := dag.NewDagReader(nd)
r, err := dag.NewDagReader(nd, nil)
if err != nil {
t.Fatal(err)
}
......@@ -42,7 +42,7 @@ func TestFileConsistencyLargeBlocks(t *testing.T) {
if err != nil {
t.Fatal(err)
}
r, err := dag.NewDagReader(nd)
r, err := dag.NewDagReader(nd, nil)
if err != nil {
t.Fatal(err)
}
......
......@@ -648,7 +648,10 @@ func (dht *IpfsDHT) peerFromInfo(pbp *PBDHTMessage_PBPeer) (*peer.Peer, error) {
}
func (dht *IpfsDHT) loadProvidableKeys() error {
kl := dht.datastore.KeyList()
kl, err := dht.datastore.KeyList()
if err != nil {
return err
}
for _, k := range kl {
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++ {
p := new(peer.Peer)
p.AddAddress(addrs[i])
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 256)
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
if err != nil {
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 {
p := new(peer.Peer)
p.AddAddress(addr)
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 256)
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
if err != nil {
panic(err)
}
......
......@@ -189,7 +189,6 @@ func TestNotFound(t *testing.T) {
// Reply with random peers to every message
fn.AddHandler(func(mes *swarm.Message) *swarm.Message {
t.Log("Handling message...")
pmes := new(PBDHTMessage)
err := proto.Unmarshal(mes.Data, pmes)
if err != nil {
......@@ -252,7 +251,6 @@ func TestLessThanKResponses(t *testing.T) {
// Reply with random peers to every message
fn.AddHandler(func(mes *swarm.Message) *swarm.Message {
t.Log("Handling message...")
pmes := new(PBDHTMessage)
err := proto.Unmarshal(mes.Data, pmes)
if err != nil {
......
......@@ -25,6 +25,8 @@ type Conn struct {
Closed chan bool
Outgoing *msgio.Chan
Incoming *msgio.Chan
secIn chan []byte
secOut chan []byte
}
// ConnMap maps Keys (Peer.IDs) to Connections.
......
......@@ -172,7 +172,7 @@ func (s *Swarm) handleNewConn(nconn net.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 {
u.PErr("%v\n", err.Error())
conn.Close()
......@@ -180,7 +180,7 @@ func (s *Swarm) handleNewConn(nconn net.Conn) {
}
// Get address to contact remote peer from
addr := <-conn.Incoming.MsgChan
addr := <-sin
maddr, err := ma.NewMultiaddr(string(addr))
if err != nil {
u.PErr("Got invalid address from peer.")
......@@ -189,6 +189,9 @@ func (s *Swarm) handleNewConn(nconn net.Conn) {
}
p.AddAddress(maddr)
conn.secIn = sin
conn.secOut = sout
err = s.StartConn(conn)
if err != nil {
s.Error(err)
......@@ -295,7 +298,7 @@ func (s *Swarm) fanOut() {
}
// 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:
goto out
case data, ok := <-conn.Incoming.MsgChan:
case data, ok := <-conn.secIn:
if !ok {
e := fmt.Errorf("Error retrieving from conn: %v", conn.Peer.Key().Pretty())
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
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 {
return err
}
......@@ -433,10 +436,13 @@ func (s *Swarm) handleDialedCon(conn *Conn) error {
myaddr := s.local.NetAddress("tcp")
mastr, err := myaddr.String()
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)
......
......@@ -89,6 +89,10 @@ func TestSwarm(t *testing.T) {
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)
// ok done, add it.
peers = append(peers, peer)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment