From a72ccbe4addde859f5f090fea45bcfdafec170f6 Mon Sep 17 00:00:00 2001 From: Darren O'Connor Date: Sun, 24 Oct 2021 10:37:42 -0400 Subject: [PATCH] More cleanup --- lib/client.go | 5 +++-- lib/server.go | 4 ++-- lib/server_test.go | 31 ++++++++++++++++--------------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/client.go b/lib/client.go index 9359ecd..877ca37 100644 --- a/lib/client.go +++ b/lib/client.go @@ -4,10 +4,11 @@ import ( "crypto/tls" "errors" "fmt" - "golang.org/x/crypto/ssh" "io" "net" "time" + + "golang.org/x/crypto/ssh" ) type RTRClientSessionEventHandler interface { @@ -221,5 +222,5 @@ func (c *ClientSession) Start(addr string, connType int, configTLS *tls.Config, } else { return errors.New(fmt.Sprintf("Unknown type %v", connType)) } - return nil + } diff --git a/lib/server.go b/lib/server.go index 8a281ca..61e601f 100644 --- a/lib/server.go +++ b/lib/server.go @@ -4,12 +4,13 @@ import ( "bytes" "crypto/tls" "fmt" - "golang.org/x/crypto/ssh" "io" "math/rand" "net" "sync" "time" + + "golang.org/x/crypto/ssh" ) func GenerateSessionId() uint16 { @@ -614,7 +615,6 @@ func (s *Server) loopTCP(tcplist net.Listener, logEnv string, clientCallback Cli } } } - return nil } func (s *Server) StartSSH(bind string, config *ssh.ServerConfig) error { diff --git a/lib/server_test.go b/lib/server_test.go index 818e778..fb320e0 100644 --- a/lib/server_test.go +++ b/lib/server_test.go @@ -2,9 +2,10 @@ package rtrlib import ( "encoding/binary" - "github.com/stretchr/testify/assert" "net" "testing" + + "github.com/stretchr/testify/assert" ) func GenerateVrps(size uint32, offset uint32) []VRP { @@ -46,7 +47,7 @@ func BenchmarkComputeDiff100000x1(b *testing.B) { func TestComputeDiff(t *testing.T) { newVrps := []VRP{ - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -54,7 +55,7 @@ func TestComputeDiff(t *testing.T) { MaxLen: 128, ASN: 65003, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -64,7 +65,7 @@ func TestComputeDiff(t *testing.T) { }, } prevVrps := []VRP{ - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -72,7 +73,7 @@ func TestComputeDiff(t *testing.T) { MaxLen: 128, ASN: 65001, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -92,7 +93,7 @@ func TestComputeDiff(t *testing.T) { func TestApplyDiff(t *testing.T) { diff := []VRP{ - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -101,7 +102,7 @@ func TestApplyDiff(t *testing.T) { ASN: 65003, Flags: FLAG_ADDED, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -110,7 +111,7 @@ func TestApplyDiff(t *testing.T) { ASN: 65002, Flags: FLAG_REMOVED, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -119,7 +120,7 @@ func TestApplyDiff(t *testing.T) { ASN: 65004, Flags: FLAG_REMOVED, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -128,7 +129,7 @@ func TestApplyDiff(t *testing.T) { ASN: 65006, Flags: FLAG_REMOVED, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -139,7 +140,7 @@ func TestApplyDiff(t *testing.T) { }, } prevVrps := []VRP{ - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -148,7 +149,7 @@ func TestApplyDiff(t *testing.T) { ASN: 65001, Flags: FLAG_ADDED, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -157,7 +158,7 @@ func TestApplyDiff(t *testing.T) { ASN: 65002, Flags: FLAG_ADDED, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -166,7 +167,7 @@ func TestApplyDiff(t *testing.T) { ASN: 65005, Flags: FLAG_REMOVED, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), @@ -175,7 +176,7 @@ func TestApplyDiff(t *testing.T) { ASN: 65006, Flags: FLAG_REMOVED, }, - VRP{ + { Prefix: net.IPNet{ IP: net.IP([]byte{0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7}), Mask: net.IPMask([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),