Skip to content

Commit

Permalink
Merge pull request #167 from dedis/router-myaddr
Browse files Browse the repository at this point in the history
Router: Accept node's address
  • Loading branch information
nkcr authored Dec 21, 2020
2 parents ff863fb + 905e4cb commit e1cc707
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mino/minogrpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (rpc RPC) Stream(ctx context.Context, players mino.Players) (mino.Sender, m
headerStreamIDKey, streamID,
headerGatewayKey, rpc.overlay.myAddrStr)

table, err := rpc.overlay.router.New(mino.NewAddresses())
table, err := rpc.overlay.router.New(mino.NewAddresses(), rpc.overlay.myAddr)
if err != nil {
return nil, nil, xerrors.Errorf("routing table failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion mino/minogrpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (r badRouter) GetHandshakeFactory() router.HandshakeFactory {
return fakeHandshakeFactory{}
}

func (badRouter) New(mino.Players) (router.RoutingTable, error) {
func (badRouter) New(mino.Players, mino.Address) (router.RoutingTable, error) {
return nil, fake.GetError()
}

Expand Down
2 changes: 1 addition & 1 deletion mino/minogrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func (o *overlayServer) tableFromHeaders(h metadata.MD) (router.RoutingTable, bo
addrs[i] = o.addrFactory.FromText([]byte(addr))
}

table, err := o.router.New(mino.NewAddresses(addrs...))
table, err := o.router.New(mino.NewAddresses(addrs...), o.myAddr)
if err != nil {
return nil, true, xerrors.Errorf("failed to create: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion mino/router/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Router interface {
GetHandshakeFactory() HandshakeFactory

// New creates a new routing table that will forward packets to the players.
New(mino.Players) (RoutingTable, error)
New(players mino.Players, me mino.Address) (RoutingTable, error)

// GenerateTableFrom returns the routing table associated to the handshake.
// A node should be able to route any incoming packet after receiving one.
Expand Down
4 changes: 2 additions & 2 deletions mino/router/tree/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func ExampleRouter_New() {

players := mino.NewAddresses(addrA, addrB)

table, err := router.New(players)
table, err := router.New(players, addrA)
if err != nil {
panic("routing table failed: " + err.Error())
}
Expand All @@ -39,7 +39,7 @@ func ExampleTable_PrepareHandshakeFor() {

players := mino.NewAddresses(addrA, addrB)

table, err := routerA.New(players)
table, err := routerA.New(players, addrA)
if err != nil {
panic("routing table failed: " + err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion mino/router/tree/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r Router) GetHandshakeFactory() router.HandshakeFactory {

// New implements router.Router. It creates the routing table for the node that
// is booting the protocol. This node will be the root of the tree.
func (r Router) New(players mino.Players) (router.RoutingTable, error) {
func (r Router) New(players mino.Players, me mino.Address) (router.RoutingTable, error) {
addrs := make([]mino.Address, 0, players.Len())
iter := players.AddressIterator()
for iter.HasNext() {
Expand Down
12 changes: 11 additions & 1 deletion mino/router/tree/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/mino"
minoRouter "go.dedis.ch/dela/mino/router"
"go.dedis.ch/dela/mino/router/tree/types"
)

Expand All @@ -27,7 +28,16 @@ func TestRouter_New(t *testing.T) {
router := NewRouter(fake.AddressFactory{})
router.maxHeight = int(height)

table, err := router.New(mino.NewAddresses(makeAddrs(int(n))...))
fakeAddrs := makeAddrs(int(n))

var table minoRouter.RoutingTable
var err error

if n > 0 {
table, err = router.New(mino.NewAddresses(fakeAddrs...), fakeAddrs[0])
} else {
table, err = router.New(mino.NewAddresses(fakeAddrs...), nil)
}
require.NoError(t, err)

return router.maxHeight == table.(Table).tree.GetMaxHeight()
Expand Down

0 comments on commit e1cc707

Please sign in to comment.