Commit 3676e634 authored by Cole Brown's avatar Cole Brown Committed by Steven Allen

Update addStream/Conn to accept a Direction

parent cdade26f
...@@ -165,7 +165,7 @@ func (s *Swarm) Process() goprocess.Process { ...@@ -165,7 +165,7 @@ func (s *Swarm) Process() goprocess.Process {
return s.proc return s.proc
} }
func (s *Swarm) addConn(tc transport.Conn, stat inet.Stat) (*Conn, error) { func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) {
// The underlying transport (or the dialer) *should* filter it's own // The underlying transport (or the dialer) *should* filter it's own
// connections but we should double check anyways. // connections but we should double check anyways.
raddr := tc.RemoteMultiaddr() raddr := tc.RemoteMultiaddr()
...@@ -194,6 +194,7 @@ func (s *Swarm) addConn(tc transport.Conn, stat inet.Stat) (*Conn, error) { ...@@ -194,6 +194,7 @@ func (s *Swarm) addConn(tc transport.Conn, stat inet.Stat) (*Conn, error) {
} }
// Wrap and register the connection. // Wrap and register the connection.
stat := inet.Stat{Direction: dir}
c := &Conn{ c := &Conn{
conn: tc, conn: tc,
swarm: s, swarm: s,
......
...@@ -100,8 +100,7 @@ func (c *Conn) start() { ...@@ -100,8 +100,7 @@ func (c *Conn) start() {
} }
c.swarm.refs.Add(1) c.swarm.refs.Add(1)
go func() { go func() {
stat := inet.Stat{Direction: inet.DirInbound} s, err := c.addStream(ts, inet.DirInbound)
s, err := c.addStream(ts, stat)
// Don't defer this. We don't want to block // Don't defer this. We don't want to block
// swarm shutdown on the connection handler. // swarm shutdown on the connection handler.
...@@ -172,11 +171,10 @@ func (c *Conn) NewStream() (inet.Stream, error) { ...@@ -172,11 +171,10 @@ func (c *Conn) NewStream() (inet.Stream, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
stat := inet.Stat{Direction: inet.DirOutbound} return c.addStream(ts, inet.DirOutbound)
return c.addStream(ts, stat)
} }
func (c *Conn) addStream(ts smux.Stream, stat inet.Stat) (*Stream, error) { func (c *Conn) addStream(ts smux.Stream, dir inet.Direction) (*Stream, error) {
c.streams.Lock() c.streams.Lock()
// Are we still online? // Are we still online?
if c.streams.m == nil { if c.streams.m == nil {
...@@ -186,6 +184,7 @@ func (c *Conn) addStream(ts smux.Stream, stat inet.Stat) (*Stream, error) { ...@@ -186,6 +184,7 @@ func (c *Conn) addStream(ts smux.Stream, stat inet.Stat) (*Stream, error) {
} }
// Wrap and register the stream. // Wrap and register the stream.
stat := inet.Stat{Direction: dir}
s := &Stream{ s := &Stream{
stream: ts, stream: ts,
conn: c, conn: c,
......
...@@ -325,8 +325,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { ...@@ -325,8 +325,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
"localAddr": connC.LocalMultiaddr(), "localAddr": connC.LocalMultiaddr(),
"remoteAddr": connC.RemoteMultiaddr(), "remoteAddr": connC.RemoteMultiaddr(),
} }
stat := inet.Stat{Direction: inet.DirOutbound} swarmC, err := s.addConn(connC, inet.DirOutbound)
swarmC, err := s.addConn(connC, stat)
if err != nil { if err != nil {
logdial["error"] = err.Error() logdial["error"] = err.Error()
connC.Close() // close the connection. didn't work out :( connC.Close() // close the connection. didn't work out :(
......
...@@ -81,8 +81,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error { ...@@ -81,8 +81,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
s.refs.Add(1) s.refs.Add(1)
go func() { go func() {
defer s.refs.Done() defer s.refs.Done()
stat := inet.Stat{Direction: inet.DirInbound} _, err := s.addConn(c, inet.DirInbound)
_, err := s.addConn(c, stat)
if err != nil { if err != nil {
// Probably just means that the swarm has been closed. // Probably just means that the swarm has been closed.
log.Warningf("add conn failed: ", err) log.Warningf("add conn failed: ", err)
......
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