Skip to content

Commit

Permalink
Tweaks as suggested by @nkryuchkov
Browse files Browse the repository at this point in the history
Actual dialing to the snettest.Env struct has also been temporarily removed. This will be addressed in #395


Former-commit-id: 67d5e6f
  • Loading branch information
evanlinjin committed Jun 7, 2020
1 parent 3981951 commit 425faa4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
10 changes: 10 additions & 0 deletions pkg/routing/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ func (br *BidirectionalRoute) ForwardAndReverse() (forward, reverse Route) {
Hops: br.Forward,
KeepAlive: br.KeepAlive,
}

reverseRoute := Route{
Desc: br.Desc.Invert(),
Hops: br.Reverse,
KeepAlive: br.KeepAlive,
}

return forwardRoute, reverseRoute
}

Expand All @@ -64,15 +66,19 @@ func (br *BidirectionalRoute) Check() error {
if len(br.Forward) == 0 {
return ErrBiRouteHasNoForwardHops
}

if len(br.Reverse) == 0 {
return ErrBiRouteHasNoReverseHops
}

if srcPK := br.Desc.SrcPK(); br.Forward[0].From != srcPK || br.Reverse[len(br.Reverse)-1].To != srcPK {
return ErrBiRouteHasInvalidDesc
}

if dstPK := br.Desc.DstPK(); br.Reverse[0].From != dstPK || br.Forward[len(br.Forward)-1].To != dstPK {
return ErrBiRouteHasInvalidDesc
}

return nil
}

Expand All @@ -84,10 +90,12 @@ func (br *BidirectionalRoute) String() string {
"fwd_hops": br.Forward,
"rev_hops": br.Reverse,
}

j, err := json.MarshalIndent(m, "", "\t")
if err != nil {
panic(err) // should never happen
}

return string(j)
}

Expand All @@ -107,10 +115,12 @@ func (er EdgeRules) String() string {
er.Reverse.String(),
},
}

j, err := json.MarshalIndent(m, "", "\t")
if err != nil {
panic(err)
}

return string(j)
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/setup/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ func biRouteFromKeys(fwdPKs, revPKs []cipher.PubKey, srcPort, dstPort routing.Po
dstPK := fwdPKs[i+1]
fwdHops[i] = routing.Hop{TpID: determineTpID(srcPK, dstPK), From: srcPK, To: dstPK}
}

revHops := make([]routing.Hop, len(revPKs)-1)
for i, srcPK := range revPKs[:len(revPKs)-1] {
dstPK := revPKs[i+1]
revHops[i] = routing.Hop{TpID: determineTpID(srcPK, dstPK), From: srcPK, To: dstPK}
}

// TODO: This should also return a map of format: map[uuid.UUID][]cipher.PubKey
// This way, we can associate transport IDs to the two transport edges, allowing for more checks.
return routing.BidirectionalRoute{
Expand All @@ -170,12 +172,14 @@ func biRouteFromKeys(fwdPKs, revPKs []cipher.PubKey, srcPort, dstPort routing.Po
// hence, we can derive the tpID from any pk pair
func determineTpID(pk1, pk2 cipher.PubKey) (tpID uuid.UUID) {
v1, v2 := pk1.Big(), pk2.Big()

var hash cipher.SHA256
if v1.Cmp(v2) > 0 {
hash = cipher.SumSHA256(append(pk1[:], pk2[:]...))
} else {
hash = cipher.SumSHA256(append(pk2[:], pk1[:]...))
}

copy(tpID[:], hash[:])
return tpID
}
Expand Down
46 changes: 25 additions & 21 deletions pkg/snet/snettest/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

"github.com/SkycoinProject/skywire-mainnet/pkg/skyenv"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/arclient"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/stcp"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/stcph"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/stcpr"
)

// KeyPair holds a public/private key pair.
Expand Down Expand Up @@ -66,18 +63,23 @@ func NewEnv(t *testing.T, keys []KeyPair, networks []string) *Env {

table := stcp.NewTable(tableEntries)

var hasDmsg, hasStcp, hasStcpr, hasStcph bool
var hasDmsg, hasStcp bool

// TODO: https://github.com/SkycoinProject/skywire-mainnet/issues/395
// var hasStcpr, hasStcph bool

for _, network := range networks {
switch network {
case dmsg.Type:
hasDmsg = true
case stcp.Type:
hasStcp = true
case stcpr.Type:
hasStcpr = true
case stcph.Type:
hasStcph = true

// TODO: https://github.com/SkycoinProject/skywire-mainnet/issues/395
// case stcpr.Type:
// hasStcpr = true
// case stcph.Type:
// hasStcph = true
}
}

Expand All @@ -94,24 +96,26 @@ func NewEnv(t *testing.T, keys []KeyPair, networks []string) *Env {
go clients.DmsgC.Serve()
}

addr := "127.0.0.1:" + strconv.Itoa(stcpBasePort+i)

addressResolver, err := arclient.NewHTTP(skyenv.TestAddressResolverAddr, pairs.PK, pairs.SK)
if err != nil {
panic(err)
}
// TODO: https://github.com/SkycoinProject/skywire-mainnet/issues/395
// addr := "127.0.0.1:" + strconv.Itoa(stcpBasePort+i)
//
// addressResolver, err := arclient.NewHTTP(skyenv.TestAddressResolverAddr, pairs.PK, pairs.SK)
// if err != nil {
// panic(err)
// }

if hasStcp {
clients.StcpC = stcp.NewClient(pairs.PK, pairs.SK, table)
}

if hasStcpr {
clients.StcprC = stcpr.NewClient(pairs.PK, pairs.SK, addressResolver, addr)
}

if hasStcph {
clients.StcphC = stcph.NewClient(pairs.PK, pairs.SK, addressResolver)
}
// TODO: https://github.com/SkycoinProject/skywire-mainnet/issues/395
// if hasStcpr {
// clients.StcprC = stcpr.NewClient(pairs.PK, pairs.SK, addressResolver, addr)
// }
//
// if hasStcph {
// clients.StcphC = stcph.NewClient(pairs.PK, pairs.SK, addressResolver)
// }

networkConfigs := snet.NetworkConfigs{
Dmsg: &snet.DmsgConfig{
Expand Down

0 comments on commit 425faa4

Please sign in to comment.