Skip to content

Commit

Permalink
Change routing.Route format
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Sep 10, 2019
1 parent 11a9b7c commit 29e28ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
20 changes: 12 additions & 8 deletions pkg/route-finder/client/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ func (r *mockClient) PairedRoutes(src, dst cipher.PubKey, minHops, maxHops uint1

return []routing.Route{
{
&routing.Hop{
TpID: transport.MakeTransportID(src, dst, ""),
From: src,
To: dst,
Hops: []routing.Hop{
{
TpID: transport.MakeTransportID(src, dst, ""),
From: src,
To: dst,
},
},
},
}, []routing.Route{
{
&routing.Hop{
TpID: transport.MakeTransportID(src, dst, ""),
From: src,
To: dst,
Hops: []routing.Hop{
{
TpID: transport.MakeTransportID(src, dst, ""),
From: src,
To: dst,
},
},
},
}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ fetchRoutesAgain:
if err != nil {
select {
case <-timer.C:
return nil, nil, err
return routing.Route{}, routing.Route{}, err
default:
goto fetchRoutesAgain
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/routing/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ type LoopDescriptor struct {

// Initiator returns initiator of the Loop.
func (l LoopDescriptor) Initiator() cipher.PubKey {
if len(l.Forward) == 0 {
if len(l.Forward.Hops) == 0 {
panic("empty forward route")
}

return l.Forward[0].From
return l.Forward.Hops[0].From
}

// Responder returns responder of the Loop.
func (l LoopDescriptor) Responder() cipher.PubKey {
if len(l.Reverse) == 0 {
if len(l.Reverse.Hops) == 0 {
panic("empty reverse route")
}

return l.Reverse[0].From
return l.Reverse.Hops[0].From
}

func (l LoopDescriptor) String() string {
Expand Down
9 changes: 7 additions & 2 deletions pkg/routing/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package routing

import (
"fmt"
"time"

"github.com/google/uuid"
"github.com/skycoin/dmsg/cipher"
Expand All @@ -21,11 +22,15 @@ func (h Hop) String() string {
}

// Route is a succession of transport entries that denotes a path from source node to destination node
type Route []*Hop
type Route struct {
Desc RouteDescriptor `json:"desc"`
Hops []Hop `json:"hops"`
KeepAlive time.Duration `json:"keep_alive"`
}

func (r Route) String() string {
res := "\n"
for _, hop := range r {
for _, hop := range r.Hops {
res += fmt.Sprintf("\t%s\n", hop)
}

Expand Down
13 changes: 6 additions & 7 deletions pkg/setup/idreservoir.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func newIDReservoir(routes ...routing.Route) (*idReservoir, int) {
var total int

for _, rt := range routes {
if len(rt) == 0 {
if len(rt.Hops) == 0 {
continue
}
rec[rt[0].From]++
for _, hop := range rt {
rec[rt.Hops[0].From]++
for _, hop := range rt.Hops {
rec[hop.To]++
}
total += len(rt) + 1
total += len(rt.Hops) + 1
}

return &idReservoir{
Expand Down Expand Up @@ -131,15 +131,14 @@ func GenerateRules(idc *idReservoir, ld routing.LoopDescriptor) (rules RulesMap,
// - lastRID: the last visor's route ID (note that there is no rule set for this ID yet).
// - err: an error (if any).
func SaveForwardRules(rules RulesMap, idc *idReservoir, keepAlive time.Duration, route routing.Route) (firstRID, lastRID routing.RouteID, err error) {

// 'firstRID' is the first visor's key routeID - this is to be returned.
var ok bool
if firstRID, ok = idc.PopID(route[0].From); !ok {
if firstRID, ok = idc.PopID(route.Hops[0].From); !ok {
return 0, 0, errors.New("fucked up")
}

var rID = firstRID
for _, hop := range route {
for _, hop := range route.Hops {
nxtRID, ok := idc.PopID(hop.To)
if !ok {
return 0, 0, errors.New("fucked up")
Expand Down

0 comments on commit 29e28ab

Please sign in to comment.