From 3da2ef04956cacac6584a7a0884e048889279d54 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 11 Dec 2019 22:10:45 +0300 Subject: [PATCH] Cleanup router --- pkg/app/appnet/skywire_networker.go | 2 +- pkg/app/appserver/proc_manager.go | 3 +-- pkg/app/appserver/server.go | 5 ++--- pkg/router/route_group.go | 17 ----------------- pkg/router/route_group_test.go | 1 + pkg/router/routerclient/client_test.go | 1 + pkg/routing/rule_test.go | 2 +- pkg/setup/idreservoir.go | 2 +- pkg/util/atomicbool/atomicbool.go | 3 ++- pkg/util/deadline/deadline.go | 3 ++- 10 files changed, 12 insertions(+), 27 deletions(-) diff --git a/pkg/app/appnet/skywire_networker.go b/pkg/app/appnet/skywire_networker.go index f3a51c941..7511f9cbc 100644 --- a/pkg/app/appnet/skywire_networker.go +++ b/pkg/app/appnet/skywire_networker.go @@ -2,13 +2,13 @@ package appnet import ( "context" + "errors" "net" "sync" "sync/atomic" "github.com/SkycoinProject/dmsg/netutil" "github.com/SkycoinProject/skycoin/src/util/logging" - "github.com/pkg/errors" "github.com/SkycoinProject/skywire-mainnet/pkg/router" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" diff --git a/pkg/app/appserver/proc_manager.go b/pkg/app/appserver/proc_manager.go index 06d2dc732..56bdacc7c 100644 --- a/pkg/app/appserver/proc_manager.go +++ b/pkg/app/appserver/proc_manager.go @@ -1,13 +1,12 @@ package appserver import ( + "errors" "fmt" "io" "os/exec" "sync" - "github.com/pkg/errors" - "github.com/SkycoinProject/skycoin/src/util/logging" "github.com/SkycoinProject/skywire-mainnet/pkg/app/appcommon" diff --git a/pkg/app/appserver/server.go b/pkg/app/appserver/server.go index e0120ba1a..df74afcc7 100644 --- a/pkg/app/appserver/server.go +++ b/pkg/app/appserver/server.go @@ -7,7 +7,6 @@ import ( "sync" "github.com/SkycoinProject/skycoin/src/util/logging" - "github.com/pkg/errors" "github.com/SkycoinProject/skywire-mainnet/pkg/app/appcommon" ) @@ -22,12 +21,12 @@ type Server struct { stopCh chan struct{} } -// NewServer constructs server. +// New constructs server. func New(log *logging.Logger, sockFile string, appKey appcommon.Key) (*Server, error) { rpcS := rpc.NewServer() gateway := NewRPCGateway(logging.MustGetLogger(fmt.Sprintf("rpc_server_%s", appKey))) if err := rpcS.RegisterName(string(appKey), gateway); err != nil { - return nil, errors.Wrap(err, "error registering RPC server for app") + return nil, fmt.Errorf("error registering RPC server for app: %v", err) } return &Server{ diff --git a/pkg/router/route_group.go b/pkg/router/route_group.go index b07dd78d4..d16d230d7 100644 --- a/pkg/router/route_group.go +++ b/pkg/router/route_group.go @@ -196,7 +196,6 @@ func (r *RouteGroup) Write(p []byte) (n int, err error) { case errCh <- tp.WritePacket(context.Background(), packet): } close(errCh) - return }() timeout := time.NewTimer(5 * time.Second) @@ -220,22 +219,6 @@ func (r *RouteGroup) Write(p []byte) (n int, err error) { } } -func (r *RouteGroup) writePacketAsync(tp *transport.ManagedTransport, packet routing.Packet) error { - var err error - var wg sync.WaitGroup - - wg.Add(1) - - go func() { - defer wg.Done() - err = tp.WritePacket(context.Background(), packet) - }() - - wg.Wait() - - return err -} - // Close closes a RouteGroup: // - Send Close packet for all ForwardRules. // - Delete all rules (ForwardRules and ConsumeRules) from routing table. diff --git a/pkg/router/route_group_test.go b/pkg/router/route_group_test.go index 68fc52175..4c057992d 100644 --- a/pkg/router/route_group_test.go +++ b/pkg/router/route_group_test.go @@ -462,6 +462,7 @@ func createRouteGroup() *RouteGroup { return rg } +// nolint:unparam func createTransports(t *testing.T, rg1, rg2 *RouteGroup, network string) (m1, m2 *transport.Manager, teardown func()) { tpDisc := transport.NewDiscoveryMock() keys := snettest.GenKeyPairs(2) diff --git a/pkg/router/routerclient/client_test.go b/pkg/router/routerclient/client_test.go index 3ea6eecaa..949c85e79 100644 --- a/pkg/router/routerclient/client_test.go +++ b/pkg/router/routerclient/client_test.go @@ -89,6 +89,7 @@ func TestClient_ReserveIDs(t *testing.T) { require.Equal(t, ids, gotIDs) } +// nolint:unparam func prepRPCServerAndClient(t *testing.T, r router.Router) (s *rpc.Server, cl *Client, cleanup func()) { l, err := nettest.NewLocalListener("tcp") require.NoError(t, err) diff --git a/pkg/routing/rule_test.go b/pkg/routing/rule_test.go index 94e4b608b..c60d0e5c2 100644 --- a/pkg/routing/rule_test.go +++ b/pkg/routing/rule_test.go @@ -35,7 +35,7 @@ func TestForwardRule(t *testing.T) { keepAlive := 2 * time.Minute pk, _ := cipher.GenerateKeyPair() - rule := ForwardRule(keepAlive, 1, 2, trID, pk, 3, 4) + rule := ForwardRule(keepAlive, 1, 2, trID, cipher.PubKey{}, pk, 3, 4) assert.Equal(t, keepAlive, rule.KeepAlive()) assert.Equal(t, RuleForward, rule.Type()) diff --git a/pkg/setup/idreservoir.go b/pkg/setup/idreservoir.go index 485123776..507d54078 100644 --- a/pkg/setup/idreservoir.go +++ b/pkg/setup/idreservoir.go @@ -107,7 +107,7 @@ func (idr *idReservoir) String() string { return string(b) } -// RulesMap associates a rule to a visor's public key. +// RuleMap associates a rule to a visor's public key. type RuleMap map[cipher.PubKey]routing.Rule // RulesMap associates a slice of rules to a visor's public key. diff --git a/pkg/util/atomicbool/atomicbool.go b/pkg/util/atomicbool/atomicbool.go index 17ed977e3..bf4dd7bba 100644 --- a/pkg/util/atomicbool/atomicbool.go +++ b/pkg/util/atomicbool/atomicbool.go @@ -1,10 +1,11 @@ package atomicbool +// Copied from https://golang.org/src/internal/poll/fd_plan9.go#L14 + import ( "sync/atomic" ) -// Copied from https://golang.org/src/internal/poll/fd_plan9.go#L14 type Bool int32 func (b *Bool) IsSet() bool { return atomic.LoadInt32((*int32)(b)) != 0 } diff --git a/pkg/util/deadline/deadline.go b/pkg/util/deadline/deadline.go index 25ea33c7f..f5269e778 100644 --- a/pkg/util/deadline/deadline.go +++ b/pkg/util/deadline/deadline.go @@ -1,6 +1,7 @@ -// Copied from https://golang.org/src/net/pipe.go with some changes. package deadline +// Copied from https://golang.org/src/net/pipe.go with some changes. + import ( "sync" "time"