|
|
@ -67,11 +67,14 @@ func (c *testTransport) close(err error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func startTestServer(t *testing.T, id discover.NodeID, pf func(*Peer)) *Server { |
|
|
|
func startTestServer(t *testing.T, id discover.NodeID, pf func(*Peer)) *Server { |
|
|
|
|
|
|
|
config := Config{ |
|
|
|
|
|
|
|
Name: "test", |
|
|
|
|
|
|
|
MaxPeers: 10, |
|
|
|
|
|
|
|
ListenAddr: "127.0.0.1:0", |
|
|
|
|
|
|
|
PrivateKey: newkey(), |
|
|
|
|
|
|
|
} |
|
|
|
server := &Server{ |
|
|
|
server := &Server{ |
|
|
|
Name: "test", |
|
|
|
Config: config, |
|
|
|
MaxPeers: 10, |
|
|
|
|
|
|
|
ListenAddr: "127.0.0.1:0", |
|
|
|
|
|
|
|
PrivateKey: newkey(), |
|
|
|
|
|
|
|
newPeerHook: pf, |
|
|
|
newPeerHook: pf, |
|
|
|
newTransport: func(fd net.Conn) transport { return newTestTransport(id, fd) }, |
|
|
|
newTransport: func(fd net.Conn) transport { return newTestTransport(id, fd) }, |
|
|
|
} |
|
|
|
} |
|
|
@ -200,10 +203,10 @@ func TestServerTaskScheduling(t *testing.T) { |
|
|
|
// The Server in this test isn't actually running
|
|
|
|
// The Server in this test isn't actually running
|
|
|
|
// because we're only interested in what run does.
|
|
|
|
// because we're only interested in what run does.
|
|
|
|
srv := &Server{ |
|
|
|
srv := &Server{ |
|
|
|
MaxPeers: 10, |
|
|
|
Config: Config{MaxPeers: 10}, |
|
|
|
quit: make(chan struct{}), |
|
|
|
quit: make(chan struct{}), |
|
|
|
ntab: fakeTable{}, |
|
|
|
ntab: fakeTable{}, |
|
|
|
running: true, |
|
|
|
running: true, |
|
|
|
} |
|
|
|
} |
|
|
|
srv.loopWG.Add(1) |
|
|
|
srv.loopWG.Add(1) |
|
|
|
go func() { |
|
|
|
go func() { |
|
|
@ -314,10 +317,12 @@ func (t *testTask) Do(srv *Server) { |
|
|
|
func TestServerAtCap(t *testing.T) { |
|
|
|
func TestServerAtCap(t *testing.T) { |
|
|
|
trustedID := randomID() |
|
|
|
trustedID := randomID() |
|
|
|
srv := &Server{ |
|
|
|
srv := &Server{ |
|
|
|
PrivateKey: newkey(), |
|
|
|
Config: Config{ |
|
|
|
MaxPeers: 10, |
|
|
|
PrivateKey: newkey(), |
|
|
|
NoDial: true, |
|
|
|
MaxPeers: 10, |
|
|
|
TrustedNodes: []*discover.Node{{ID: trustedID}}, |
|
|
|
NoDial: true, |
|
|
|
|
|
|
|
TrustedNodes: []*discover.Node{{ID: trustedID}}, |
|
|
|
|
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
if err := srv.Start(); err != nil { |
|
|
|
if err := srv.Start(); err != nil { |
|
|
|
t.Fatalf("could not start: %v", err) |
|
|
|
t.Fatalf("could not start: %v", err) |
|
|
@ -415,10 +420,12 @@ func TestServerSetupConn(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
for i, test := range tests { |
|
|
|
for i, test := range tests { |
|
|
|
srv := &Server{ |
|
|
|
srv := &Server{ |
|
|
|
PrivateKey: srvkey, |
|
|
|
Config: Config{ |
|
|
|
MaxPeers: 10, |
|
|
|
PrivateKey: srvkey, |
|
|
|
NoDial: true, |
|
|
|
MaxPeers: 10, |
|
|
|
Protocols: []Protocol{discard}, |
|
|
|
NoDial: true, |
|
|
|
|
|
|
|
Protocols: []Protocol{discard}, |
|
|
|
|
|
|
|
}, |
|
|
|
newTransport: func(fd net.Conn) transport { return test.tt }, |
|
|
|
newTransport: func(fd net.Conn) transport { return test.tt }, |
|
|
|
} |
|
|
|
} |
|
|
|
if !test.dontstart { |
|
|
|
if !test.dontstart { |
|
|
|