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