@cryptotaxi247 / kubo / commits / 31a3c4497

swarm fixes

Juan Batiz-Benet committed Dec 16, 2014 at 03:34 UTC 31a3c4497aa3ed165eadd64aff050c39417897de
4 files changed +21 -10
net/swarm2/simul_test.go
+4 -4
@@ -12,7 +12,7 @@ import (
12 )
13
14 func TestSimultOpen(t *testing.T) {
15 - t.Skip("skipping for another test")
15 + // t.Skip("skipping for another test")
16
17 addrs := []string{
18 "/ip4/127.0.0.1/tcp/1244",
@@ -49,9 +49,9 @@ func TestSimultOpen(t *testing.T) {
49 }
50
51 func TestSimultOpenMany(t *testing.T) {
52 - t.Skip("very very slow")
52 + // t.Skip("very very slow")
53
54 - many := 500
54 + many := 10
55 addrs := []string{}
56 for i := 2200; i < (2200 + many); i++ {
57 s := fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", i)
@@ -65,7 +65,7 @@ func TestSimultOpenFewStress(t *testing.T) {
65 if testing.Short() {
66 t.SkipNow()
67 }
68 - t.Skip("skipping for another test")
68 + // t.Skip("skipping for another test")
69
70 num := 10
71 // num := 100
net/swarm2/swarm.go
+8
@@ -70,6 +70,14 @@ func (s *Swarm) SetStreamHandler(handler StreamHandler) {
70
71 // NewStreamWithPeer creates a new stream on any available connection to p
72 func (s *Swarm) NewStreamWithPeer(p peer.Peer) (*Stream, error) {
73 +
74 + // if we have no connections, try connecting.
75 + if len(s.ConnectionsToPeer(p)) == 0 {
76 + if _, err := s.Dial(p); err != nil {
77 + return nil, err
78 + }
79 + }
80 +
81 st, err := s.swarm.NewStreamWithGroup(p)
82 return wrapStream(st), err
83 }
net/swarm2/swarm_conn.go
+5 -5
@@ -14,11 +14,11 @@ import (
14 // a Conn is a simple wrapper around a ps.Conn that also exposes
15 // some of the methods from the underlying conn.Conn.
16 // There's **five** "layers" to each connection:
17 -// - 0. the net.Conn - underlying net.Conn (TCP/UDP/UTP/etc)
18 -// - 1. the manet.Conn - provides multiaddr friendly Conn
19 -// - 2. the conn.Conn - provides Peer friendly Conn (inc Secure channel)
20 -// - 3. the peerstream.Conn - provides peerstream / spdysptream happiness
21 -// - 4. the Conn - abstracts everyting out, exposing only key parts of underlying layers
17 +// * 0. the net.Conn - underlying net.Conn (TCP/UDP/UTP/etc)
18 +// * 1. the manet.Conn - provides multiaddr friendly Conn
19 +// * 2. the conn.Conn - provides Peer friendly Conn (inc Secure channel)
20 +// * 3. the peerstream.Conn - provides peerstream / spdysptream happiness
21 +// * 4. the Conn - abstracts everyting out, exposing only key parts of underlying layers
22 // (I know, this is kinda crazy. it's more historical than a good design. though the
23 // layers do build up pieces of functionality. and they're all just io.RW :) )
24 type Conn ps.Conn
net/swarm2/swarm_listen.go
+4 -1
@@ -18,12 +18,15 @@ func (s *Swarm) listen(addrs []ma.Multiaddr) error {
18 for i, addr := range addrs {
19 err := s.setupListener(addr)
20 if err != nil {
21 + if retErr.Errors == nil {
22 + retErr.Errors = make([]error, len(addrs))
23 + }
24 retErr.Errors[i] = err
25 log.Errorf("Failed to listen on: %s - %s", addr, err)
26 }
27 }
28
26 - if len(retErr.Errors) > 0 {
29 + if retErr.Errors != nil {
30 return retErr
31 }
32 return nil