merge wind HoC
Juan Batiz-Benet committed
Sep 14, 2014 at 04:28 UTC
f71be6e9cc68412503e979601e285b77f2874f50
2 files changed
+23
-12
net/conn/conn.go
+3
-2
@@ -6,6 +6,8 @@ import (
6
7
msgio "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio"
8
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
9
+
10
+ spipe "github.com/jbenet/go-ipfs/crypto/spipe"
11
peer "github.com/jbenet/go-ipfs/peer"
12
u "github.com/jbenet/go-ipfs/util"
13
)
@@ -25,8 +27,7 @@ type Conn struct {
27
Closed chan bool
28
Outgoing *msgio.Chan
29
Incoming *msgio.Chan
28
- secIn <-chan []byte
29
- secOut chan<- []byte
30
+ Secure *spipe.SecurePipe
31
}
32
33
// Map maps Keys (Peer.IDs) to Connections.
net/swarm/conn.go
+20
-10
@@ -5,7 +5,7 @@ import (
5
"fmt"
6
"net"
7
8
- ident "github.com/jbenet/go-ipfs/identify"
8
+ spipe "github.com/jbenet/go-ipfs/crypto/spipe"
9
conn "github.com/jbenet/go-ipfs/net/conn"
10
msg "github.com/jbenet/go-ipfs/net/message"
11
u "github.com/jbenet/go-ipfs/util"
@@ -103,10 +103,9 @@ func (s *Swarm) connSetup(c *conn.Conn) error {
103
104
u.DOut("Starting connection: %s\n", c.Peer.Key().Pretty())
105
106
- // handshake TODO(jbenet) enable handshake
107
- // if err := s.connHandshake(c); err != nil {
108
- // return fmt.Errorf("Conn handshake error: %v", err)
109
- // }
106
+ if err := s.connSecure(c); err != nil {
107
+ return fmt.Errorf("Conn securing error: %v", err)
108
+ }
109
110
// add to conns
111
s.connsLock.Lock()
@@ -122,12 +121,23 @@ func (s *Swarm) connSetup(c *conn.Conn) error {
121
return nil
122
}
123
125
-// connHandshake runs the handshake with the remote connection.
126
-func (s *Swarm) connHandshake(c *conn.Conn) error {
124
+// connSecure setups a secure remote connection.
125
+func (s *Swarm) connSecure(c *conn.Conn) error {
126
+
127
+ sp, err := spipe.NewSecurePipe(s.ctx, 10, s.local, c.Peer)
128
+ if err != nil {
129
+ return err
130
+ }
131
+
132
+ err = sp.Wrap(s.ctx, spipe.Duplex{
133
+ In: c.Incoming.MsgChan,
134
+ Out: c.Outgoing.MsgChan,
135
+ })
136
+ if err != nil {
137
+ return err
138
+ }
139
128
- //TODO(jbenet) this Handshake stuff should be moved elsewhere.
129
- // needs cleanup. needs context. use msg.Pipe.
130
- return ident.Handshake(s.local, c.Peer, c.Incoming.MsgChan, c.Outgoing.MsgChan)
140
+ return nil
141
}
142
143
// Handles the unwrapping + sending of messages to the right connection.