diff --git a/net/swarm2/simul_test.go b/net/swarm2/simul_test.go index ed5e58618..bf6f55aae 100644 --- a/net/swarm2/simul_test.go +++ b/net/swarm2/simul_test.go @@ -12,7 +12,7 @@ import ( ) func TestSimultOpen(t *testing.T) { - t.Skip("skipping for another test") + // t.Skip("skipping for another test") addrs := []string{ "/ip4/127.0.0.1/tcp/1244", @@ -49,9 +49,9 @@ func TestSimultOpen(t *testing.T) { } func TestSimultOpenMany(t *testing.T) { - t.Skip("very very slow") + // t.Skip("very very slow") - many := 500 + many := 10 addrs := []string{} for i := 2200; i < (2200 + many); i++ { s := fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", i) @@ -65,7 +65,7 @@ func TestSimultOpenFewStress(t *testing.T) { if testing.Short() { t.SkipNow() } - t.Skip("skipping for another test") + // t.Skip("skipping for another test") num := 10 // num := 100 diff --git a/net/swarm2/swarm.go b/net/swarm2/swarm.go index 28ec36c90..4fa6399ea 100644 --- a/net/swarm2/swarm.go +++ b/net/swarm2/swarm.go @@ -70,6 +70,14 @@ func (s *Swarm) SetStreamHandler(handler StreamHandler) { // NewStreamWithPeer creates a new stream on any available connection to p func (s *Swarm) NewStreamWithPeer(p peer.Peer) (*Stream, error) { + + // if we have no connections, try connecting. + if len(s.ConnectionsToPeer(p)) == 0 { + if _, err := s.Dial(p); err != nil { + return nil, err + } + } + st, err := s.swarm.NewStreamWithGroup(p) return wrapStream(st), err } diff --git a/net/swarm2/swarm_conn.go b/net/swarm2/swarm_conn.go index 3017cf54d..f0502a7de 100644 --- a/net/swarm2/swarm_conn.go +++ b/net/swarm2/swarm_conn.go @@ -14,11 +14,11 @@ import ( // a Conn is a simple wrapper around a ps.Conn that also exposes // some of the methods from the underlying conn.Conn. // There's **five** "layers" to each connection: -// - 0. the net.Conn - underlying net.Conn (TCP/UDP/UTP/etc) -// - 1. the manet.Conn - provides multiaddr friendly Conn -// - 2. the conn.Conn - provides Peer friendly Conn (inc Secure channel) -// - 3. the peerstream.Conn - provides peerstream / spdysptream happiness -// - 4. the Conn - abstracts everyting out, exposing only key parts of underlying layers +// * 0. the net.Conn - underlying net.Conn (TCP/UDP/UTP/etc) +// * 1. the manet.Conn - provides multiaddr friendly Conn +// * 2. the conn.Conn - provides Peer friendly Conn (inc Secure channel) +// * 3. the peerstream.Conn - provides peerstream / spdysptream happiness +// * 4. the Conn - abstracts everyting out, exposing only key parts of underlying layers // (I know, this is kinda crazy. it's more historical than a good design. though the // layers do build up pieces of functionality. and they're all just io.RW :) ) type Conn ps.Conn diff --git a/net/swarm2/swarm_listen.go b/net/swarm2/swarm_listen.go index 247725903..7ba3a01c3 100644 --- a/net/swarm2/swarm_listen.go +++ b/net/swarm2/swarm_listen.go @@ -18,12 +18,15 @@ func (s *Swarm) listen(addrs []ma.Multiaddr) error { for i, addr := range addrs { err := s.setupListener(addr) if err != nil { + if retErr.Errors == nil { + retErr.Errors = make([]error, len(addrs)) + } retErr.Errors[i] = err log.Errorf("Failed to listen on: %s - %s", addr, err) } } - if len(retErr.Errors) > 0 { + if retErr.Errors != nil { return retErr } return nil