Skip to content

Commit

Permalink
Cleanup router
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Dec 12, 2019
1 parent d344eda commit 3da2ef0
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pkg/app/appnet/skywire_networker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions pkg/app/appserver/proc_manager.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 2 additions & 3 deletions pkg/app/appserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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{
Expand Down
17 changes: 0 additions & 17 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/router/route_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/router/routerclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/routing/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/setup/idreservoir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/atomicbool/atomicbool.go
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/deadline/deadline.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 3da2ef0

Please sign in to comment.