diff options
author | Andrey Petrov <andrey.petrov@shazow.net> | 2018-03-19 00:25:35 +0800 |
---|---|---|
committer | Andrey Petrov <andrey.petrov@shazow.net> | 2018-06-22 00:21:48 +0800 |
commit | 773857a5242a3fe7458a9c9b60a4ea6333582e56 (patch) | |
tree | c4024f48bbe763c21a6d3596d49f269b1c9f92a4 /p2p/server_test.go | |
parent | 2a75fe3308faf4d77054e00b55566c9f18591572 (diff) | |
download | go-tangerine-773857a5242a3fe7458a9c9b60a4ea6333582e56.tar go-tangerine-773857a5242a3fe7458a9c9b60a4ea6333582e56.tar.gz go-tangerine-773857a5242a3fe7458a9c9b60a4ea6333582e56.tar.bz2 go-tangerine-773857a5242a3fe7458a9c9b60a4ea6333582e56.tar.lz go-tangerine-773857a5242a3fe7458a9c9b60a4ea6333582e56.tar.xz go-tangerine-773857a5242a3fe7458a9c9b60a4ea6333582e56.tar.zst go-tangerine-773857a5242a3fe7458a9c9b60a4ea6333582e56.zip |
p2p: Test for MaxPeers=0 and TrustedPeer override
Diffstat (limited to 'p2p/server_test.go')
-rw-r--r-- | p2p/server_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/p2p/server_test.go b/p2p/server_test.go index 10c36528e..efab9bb5e 100644 --- a/p2p/server_test.go +++ b/p2p/server_test.go @@ -363,7 +363,61 @@ func TestServerAtCap(t *testing.T) { if !c.is(trustedConn) { t.Error("Server did not set trusted flag") } +} + +func TestServerPeerLimits(t *testing.T) { + srvkey := newkey() + srvid := discover.PubkeyID(&srvkey.PublicKey) + + var tp *setupTransport = &setupTransport{id: srvid, phs: &protoHandshake{ID: srvid}} + var flags connFlag = dynDialedConn + var dialDest *discover.Node = &discover.Node{ID: srvid} + srv := &Server{ + Config: Config{ + PrivateKey: srvkey, + MaxPeers: 0, + NoDial: true, + Protocols: []Protocol{discard}, + }, + newTransport: func(fd net.Conn) transport { return tp }, + log: log.New(), + } + if err := srv.Start(); err != nil { + t.Fatalf("couldn't start server: %v", err) + } + + // Check that server is full (MaxPeers=0) + conn, _ := net.Pipe() + srv.SetupConn(conn, flags, dialDest) + if tp.closeErr != DiscTooManyPeers { + t.Errorf("unexpected close error: %q", tp.closeErr) + } + conn.Close() + + srv.AddTrustedPeer(dialDest) + + // Check that server allows a trusted peer despite being full. + conn, _ = net.Pipe() + srv.SetupConn(conn, flags, dialDest) + if tp.closeErr == DiscTooManyPeers { + t.Errorf("failed to bypass MaxPeers with trusted node: %q", tp.closeErr) + } + + if tp.closeErr != DiscSelf { + t.Errorf("unexpected close error: %q", tp.closeErr) + } + conn.Close() + + srv.RemoveTrustedPeer(dialDest) + + // Check that server is full again. + conn, _ = net.Pipe() + srv.SetupConn(conn, flags, dialDest) + if tp.closeErr != DiscTooManyPeers { + t.Errorf("unexpected close error: %q", tp.closeErr) + } + conn.Close() } func TestServerSetupConn(t *testing.T) { |