diff --git a/pkg/routing/route.go b/pkg/routing/route.go index 162aff946..e142d7abe 100644 --- a/pkg/routing/route.go +++ b/pkg/routing/route.go @@ -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 } @@ -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 } @@ -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) } @@ -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) } diff --git a/pkg/setup/node_test.go b/pkg/setup/node_test.go index ed83fe3f9..0367efa93 100644 --- a/pkg/setup/node_test.go +++ b/pkg/setup/node_test.go @@ -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{ @@ -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 } diff --git a/pkg/snet/snettest/env.go b/pkg/snet/snettest/env.go index dd8015056..a87d8f4af 100644 --- a/pkg/snet/snettest/env.go +++ b/pkg/snet/snettest/env.go @@ -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. @@ -66,7 +63,10 @@ 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 { @@ -74,10 +74,12 @@ func NewEnv(t *testing.T, keys []KeyPair, networks []string) *Env { 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 } } @@ -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{