diff --git a/cmd/route-finder/README.md b/cmd/route-finder/README.md index e09b0b51..66517457 100644 --- a/cmd/route-finder/README.md +++ b/cmd/route-finder/README.md @@ -1,5 +1,8 @@ # Route finder +## Definitions of `hop` term +In general graph theory, a **hop** refers to the traversal from one vertex to another via an edge. But here, we consider hop as visors between source and destination. For example, for A -> B -> C -> D -> E, number of hops from visor A to E is 3. + ## API endpoints ### GET `/health` @@ -27,4 +30,4 @@ Body: "max_hops": 0 } } -``` \ No newline at end of file +``` diff --git a/docker/config/dmsg-monitor.json b/docker/config/dmsg-monitor.json index 318d6e03..d5a69235 100644 --- a/docker/config/dmsg-monitor.json +++ b/docker/config/dmsg-monitor.json @@ -5,7 +5,8 @@ "dmsg": { "discovery": "http://dmsg-discovery:9090", "sessions_count": 1, - "servers": [] + "servers": [], + "servers_type": "all" }, "transport": { "discovery": "http://transport-discovery:9091", diff --git a/docker/config/network-monitor.json b/docker/config/network-monitor.json index e35cc507..505f19c4 100644 --- a/docker/config/network-monitor.json +++ b/docker/config/network-monitor.json @@ -5,7 +5,8 @@ "dmsg": { "discovery": "http://dmsg-discovery:9090", "sessions_count": 1, - "servers": [] + "servers": [], + "servers_type": "all" }, "transport": { "discovery": "http://transport-discovery:9091", diff --git a/docker/config/public-visor-monitor.json b/docker/config/public-visor-monitor.json index c56a9507..ee7e33d0 100644 --- a/docker/config/public-visor-monitor.json +++ b/docker/config/public-visor-monitor.json @@ -5,7 +5,8 @@ "dmsg": { "discovery": "http://dmsg-discovery:9090", "sessions_count": 1, - "servers": [] + "servers": [], + "servers_type": "all" }, "transport": { "discovery": "http://transport-discovery:9091", diff --git a/docker/config/skysocks-monitor.json b/docker/config/skysocks-monitor.json index d2679535..939c72f6 100644 --- a/docker/config/skysocks-monitor.json +++ b/docker/config/skysocks-monitor.json @@ -5,7 +5,8 @@ "dmsg": { "discovery": "http://dmsg-discovery:9090", "sessions_count": 1, - "servers": [] + "servers": [], + "servers_type": "all" }, "transport": { "discovery": "http://transport-discovery:9091", diff --git a/docker/config/tpd-monitor.json b/docker/config/tpd-monitor.json index 615c85bf..c486f24b 100644 --- a/docker/config/tpd-monitor.json +++ b/docker/config/tpd-monitor.json @@ -5,7 +5,8 @@ "dmsg": { "discovery": "http://dmsg-discovery:9090", "sessions_count": 1, - "servers": [] + "servers": [], + "servers_type": "all" }, "transport": { "discovery": "http://transport-discovery:9091", diff --git a/docker/config/vpn-monitor.json b/docker/config/vpn-monitor.json index 9e7b855a..c3bfe71e 100644 --- a/docker/config/vpn-monitor.json +++ b/docker/config/vpn-monitor.json @@ -5,7 +5,8 @@ "dmsg": { "discovery": "http://dmsg-discovery:9090", "sessions_count": 1, - "servers": [] + "servers": [], + "servers_type": "all" }, "transport": { "discovery": "http://transport-discovery:9091", diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 93930f04..891a75f6 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -357,7 +357,7 @@ services: ipv4_address: 174.0.0.17 ports: - "9089:9089" - entrypoint: "/release/node-visualizer --ut-url http://uptime-tracker:9096 --tpd-url http://transport-discovery:9091" + entrypoint: "/release/node-visualizer --ut-url http://uptime-tracker:9096/uptimes?status=on --tpd-url http://transport-discovery:9091/all-transports?selfTransports=hide" depends_on: - transport-discovery - uptime-tracker @@ -451,7 +451,7 @@ services: - visor-a restart: always entrypoint: /release/skywire visor -c /opt/skywire/skywire-visor.json - + network-monitor: image: "${REGISTRY}/network-monitor:${DOCKER_TAG}" hostname: network-monitor diff --git a/docker/images/service-discovery/Dockerfile b/docker/images/service-discovery/Dockerfile index 07589f19..13e09b01 100644 --- a/docker/images/service-discovery/Dockerfile +++ b/docker/images/service-discovery/Dockerfile @@ -8,8 +8,6 @@ RUN apk --no-cache add bash curl ARG CGO_ENABLED=0 ENV CGO_ENABLED=${CGO_ENABLED} \ - GOOS=linux \ - GOARCH=amd64 \ GO111MODULE=on COPY /docker/common/install-prequisites.sh /install-prequisites.sh diff --git a/docker/integration/visorA.json b/docker/integration/visorA.json index 33a853c7..7dcc5821 100755 --- a/docker/integration/visorA.json +++ b/docker/integration/visorA.json @@ -93,6 +93,6 @@ "stun_servers": null, "shutdown_timeout": "30s", "restart_check_delay": "1s", - "is_public": true, + "is_public": false, "persistent_transports": null } diff --git a/docker/integration/visorC.json b/docker/integration/visorC.json index e900a253..5c591a84 100755 --- a/docker/integration/visorC.json +++ b/docker/integration/visorC.json @@ -5,7 +5,8 @@ "dmsg": { "discovery": "http://dmsg-discovery:9090", "sessions_count": 1, - "servers": [] + "servers": [], + "servers_type": "all" }, "dmsgpty": { "dmsg_port": 22, @@ -22,8 +23,8 @@ "address_resolver": "http://address-resolver:9093", "public_autoconnect": false, "transport_setup_nodes": [ - "0277dda8a284d43b4d5ee2a4152771e76131e9437c47be5d8e835aafe02c45a9ae" - ], + "0277dda8a284d43b4d5ee2a4152771e76131e9437c47be5d8e835aafe02c45a9ae" + ], "log_store": { "type": "file", "location": "./local/transport_logs", @@ -85,6 +86,16 @@ "auto_start": true, "port": 13 }, + { + "name": "skysocks", + "binary": "skywire", + "args": [ + "app", + "skysocks" + ], + "auto_start": true, + "port": 3 + }, { "name": "vpn-server", "binary": "skywire", @@ -110,7 +121,6 @@ "dmsghttp_server_path": "./local/custom", "stun_servers": null, "shutdown_timeout": "30s", - "restart_check_delay": "1s", "is_public": false, "persistent_transports": null } diff --git a/pkg/node-visualizer/api/api.go b/pkg/node-visualizer/api/api.go index ec1f0667..63acd042 100644 --- a/pkg/node-visualizer/api/api.go +++ b/pkg/node-visualizer/api/api.go @@ -154,7 +154,7 @@ func fetchNodes(utURL string) error { } // createGraph creates a graph from the transport data -func createGraph() ([]map[string]interface{}, error) { +func createGraph(debug bool) ([]map[string]interface{}, error) { mu.Lock() defer mu.Unlock() @@ -171,18 +171,26 @@ func createGraph() ([]map[string]interface{}, error) { if !exist { nodeMap[edgeA] = nodeID nodeID++ + label := "" + if debug { + label = edgeA + } nodes = append(nodes, map[string]interface{}{ "id": edgeA, - "label": "", + "label": label, }) } _, exist = nodeMap[edgeB] if !exist { nodeMap[edgeB] = nodeID nodeID++ + label := "" + if debug { + label = edgeB + } nodes = append(nodes, map[string]interface{}{ "id": edgeB, - "label": "", + "label": label, }) } @@ -197,9 +205,13 @@ func createGraph() ([]map[string]interface{}, error) { if !exist { nodeMap[utItem.Key] = nodeID nodeID++ + label := "" + if debug { + label = utItem.Key + } nodes = append(nodes, map[string]interface{}{ "id": utItem.Key, - "label": "", + "label": label, }) } } @@ -223,8 +235,14 @@ func graphHandler(w http.ResponseWriter, r *http.Request) { return } + var debug bool + query := r.URL.Query() + selfTransportsParam := query.Get("debug") + if selfTransportsParam == "true" { + debug = true + } // Create the graph - graph, err := createGraph() + graph, err := createGraph(debug) if err != nil { http.Error(w, fmt.Sprintf("Failed to create graph: %v", err), http.StatusInternalServerError) return diff --git a/pkg/route-finder/api/api.go b/pkg/route-finder/api/api.go index 9095b3ce..5acaeb6c 100644 --- a/pkg/route-finder/api/api.go +++ b/pkg/route-finder/api/api.go @@ -21,7 +21,7 @@ import ( "github.com/skycoin/skywire-services/pkg/transport-discovery/store" ) -const maxNumberOfRoutes = 5 +const maxNumberOfRoutes = 3 // API represents the api of the route-finder service. type API struct { @@ -139,7 +139,7 @@ func (a *API) getPairedRoutes(w http.ResponseWriter, r *http.Request) { dstPK := edge[1] graph := graphs[srcPK] - forwardRoutes, err := graph.Shortest(r.Context(), srcPK, dstPK, minHops, maxHops, maxNumberOfRoutes) + forwardRoutes, err := graph.GetRoute(r.Context(), srcPK, dstPK, minHops, maxHops, maxNumberOfRoutes) if err != nil { a.handleError(w, r, http.StatusNotFound, err) return diff --git a/pkg/route-finder/store/dijkstra.go b/pkg/route-finder/store/dijkstra.go deleted file mode 100644 index 0ab4e60c..00000000 --- a/pkg/route-finder/store/dijkstra.go +++ /dev/null @@ -1,165 +0,0 @@ -// Package store pkg/route-finder/store/dijkstra.go -package store - -import ( - "container/heap" - "context" - "errors" - "sort" - - "github.com/skycoin/skywire/pkg/routing" - "github.com/skycoin/skywire/pkg/skywire-utilities/pkg/cipher" -) - -// package level errors -var ( - ErrNoRoute = errors.New("no route to destination") - ErrContextClosed = errors.New("context closed or timed out") - ErrRouteNotFound = errors.New("route not found") -) - -// dist is constant for now, can be latencies in a new implementation -const ( - infinity = int(^uint(0) >> 1) - distBetweenNodes = 1 -) - -// Shortest returns a set of max number shortest routes from source to destination which length is between minLen and -// maxLen -func (g *Graph) Shortest(ctx context.Context, source, destination cipher.PubKey, minLen, maxLen, number int) (routes []routing.Route, err error) { - sourceVertex, ok := g.graph[source] - if !ok { - return nil, ErrNoRoute - } - - destinationVertex, ok := g.graph[destination] - if !ok { - return nil, ErrNoRoute - } - - previousNodes, err := g.dijkstra(ctx, sourceVertex, destinationVertex) - if err != nil { - return nil, err - } - return g.routes(ctx, previousNodes, destinationVertex, minLen, maxLen, number) -} - -type previousNode struct { - distToDestination int - previous *vertex -} - -// Implement node version of: https://rosettacode.org/wiki/Dijkstra%27s_algorithm#Go -// dijkstra computes optimal paths from source node to every other node, but it keeps track of every other -// suboptimal route to destination and returns them -func (g *Graph) dijkstra(ctx context.Context, source, destination *vertex) ([]previousNode, error) { - dist := make(map[*vertex]int) - prev := make(map[*vertex]*vertex) - destinationPrev := make([]previousNode, 0) - - sid := source - dist[sid] = 0 - q := &priorityQueue{[]*vertex{}, make(map[*vertex]int), make(map[*vertex]int)} - for _, v := range g.graph { - select { - case <-ctx.Done(): - return nil, ErrContextClosed - default: - if v != sid { - dist[v] = infinity - } - prev[v] = nil - q.addWithPriority(v, dist[v]) - } - } - for len(q.items) != 0 { - select { - case <-ctx.Done(): - return nil, ErrContextClosed - default: - u := heap.Pop(q).(*vertex) - // Process only if there is a path from root (dist < infinity) - if dist[u] < infinity { - for _, v := range u.neighbors { - if v == destination { - alt := dist[u] + distBetweenNodes - pn := previousNode{alt, u} - destinationPrev = append(destinationPrev, pn) - } else { - alt := dist[u] + distBetweenNodes - if alt < dist[v] { - dist[v] = alt - prev[v] = u - q.update(v, alt) - } - } - } - } - } - } - - g.dist = dist - g.prev = prev - - return destinationPrev, nil -} - -// Route sorts by length and backtraces every route from destination to source. Only adds the paths -// with length between minLen and maxLen and returns a maximum of number routes -func (g *Graph) routes(ctx context.Context, previousNodes []previousNode, destination *vertex, minLen, maxLen, number int) ([]routing.Route, error) { - // Sort - sort.Slice(previousNodes, func(i, j int) bool { - return previousNodes[i].distToDestination < previousNodes[j].distToDestination - }) - - // Backtrace - routes := make([]routing.Route, 0) - - for _, prev := range previousNodes { - if len(routes) == number { - break - } - - select { - case <-ctx.Done(): - return nil, ErrContextClosed - default: - if prev.distToDestination >= minLen && prev.distToDestination <= maxLen { - var route routing.Route - hop := routing.Hop{ - From: prev.previous.edge, - To: destination.edge, - TpID: prev.previous.connections[destination.edge].ID, - } - route.Hops = append(route.Hops, hop) - prevVertex := prev.previous - for g.prev[prevVertex] != nil { - hop := routing.Hop{ - From: g.prev[prevVertex].edge, - To: prevVertex.edge, - TpID: g.prev[prevVertex].connections[prevVertex.edge].ID, - } - route.Hops = append(route.Hops, hop) - prevVertex = g.prev[prevVertex] - } - - // because we are backtracking routes are reversed - route = reverseRoute(route) - routes = append(routes, route) - } - } - } - - if len(routes) == 0 { - return nil, ErrRouteNotFound - } - return routes, nil -} - -func reverseRoute(r routing.Route) routing.Route { - for left, right := 0, len(r.Hops)-1; left < right; left, right = left+1, right-1 { - r.Hops[left], r.Hops[right] = r.Hops[right], r.Hops[left] - } - - return r -} diff --git a/pkg/route-finder/store/finder.go b/pkg/route-finder/store/finder.go new file mode 100644 index 00000000..3941e5a6 --- /dev/null +++ b/pkg/route-finder/store/finder.go @@ -0,0 +1,128 @@ +// Package store pkg/route-finder/store/finder.go +package store + +import ( + "context" + "errors" + "fmt" + + "github.com/skycoin/skywire/pkg/routing" + "github.com/skycoin/skywire/pkg/skywire-utilities/pkg/cipher" +) + +// package level errors +var ( + ErrNoRoute = errors.New("no route to destination") + ErrContextClosed = errors.New("context closed or timed out") +) + +// GetRoute returns a set of max number routes from source to destination which length is between minLen and +// maxLen +func (g *Graph) GetRoute(ctx context.Context, source, destination cipher.PubKey, minLen, maxLen, number int) (routes []routing.Route, err error) { + sourceVertex, ok := g.graph[source] + if !ok { + return nil, ErrNoRoute + } + + destinationVertex, ok := g.graph[destination] + if !ok { + return nil, ErrNoRoute + } + return g.routes(ctx, sourceVertex, destinationVertex, minLen, maxLen, number) +} + +func (g *Graph) routes(ctx context.Context, source, destination *vertex, minLen, maxLen, number int) ([]routing.Route, error) { + type queueElement struct { + node *vertex + path []*vertex + } + + routes := make([]routing.Route, 0) + queue := []queueElement{{source, []*vertex{source}}} + + visited := make(map[*vertex]bool) + visited[source] = true + + for len(queue) > 0 && len(routes) < number { + select { + case <-ctx.Done(): + return nil, ErrContextClosed + default: + // Dequeue the first element + current := queue[0] + queue = queue[1:] + + // If the current path exceeds maxHops, skip this path + if len(current.path)-1 > maxLen { + continue + } + + // If we reached the target and the path satisfies minHops, add it to validPaths + if current.node == destination && len(current.path)-1 >= minLen { + routes = g.appendRoute(ctx, routes, current.path) + } + // Explore all neighbors + for _, neighbor := range g.graph { + select { + case <-ctx.Done(): + return nil, ErrContextClosed + default: + if current.node.edge.Hex() == neighbor.edge.Hex() { + continue + } + if !visited[neighbor] { + visited[neighbor] = true + newPath := append([]*vertex{}, current.path...) + if !containsVertex(newPath, neighbor) { + newPath = append(newPath, neighbor) + queue = append(queue, queueElement{neighbor, newPath}) + } + visited[neighbor] = false + } + } + } + } + } + + if len(routes) == 0 { + return nil, fmt.Errorf("no route found from %s to %s with at least %d hops and at most %d hops", source.edge.Hex(), destination.edge.Hex(), minLen, maxLen) + } + + return routes, nil +} + +func (g *Graph) appendRoute(ctx context.Context, routes []routing.Route, path []*vertex) []routing.Route { + var route routing.Route + for i, v := range path { + select { + case <-ctx.Done(): + return nil + default: + if i == len(path)-1 { + continue + } + if _, ok := v.connections[path[i+1].edge]; !ok { + continue + } + hop := routing.Hop{ + From: v.edge, + To: path[i+1].edge, + TpID: v.connections[path[i+1].edge].ID, + } + route.Hops = append(route.Hops, hop) + } + } + if len(route.Hops) == len(path)-1 { + routes = append(routes, route) + } + return routes +} + +func containsVertex(slice []*vertex, element *vertex) bool { + for _, item := range slice { + if item == element { + return true + } + } + return false +} diff --git a/pkg/route-finder/store/dijkstra_test.go b/pkg/route-finder/store/finder_test.go similarity index 83% rename from pkg/route-finder/store/dijkstra_test.go rename to pkg/route-finder/store/finder_test.go index b72715e5..23d52969 100644 --- a/pkg/route-finder/store/dijkstra_test.go +++ b/pkg/route-finder/store/finder_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestDijkstra(t *testing.T) { +func TestFinder(t *testing.T) { node1PK, node2PK, node3PK, node4PK, node5PK := generateNodesPK(t) m := newMockStore() @@ -23,20 +23,20 @@ func TestDijkstra(t *testing.T) { g, err := NewGraph(context.TODO(), m, node1PK) require.NoError(t, err) - routes, err := g.Shortest(context.TODO(), node1PK, node5PK, 0, 100, 5) + routes, err := g.GetRoute(context.TODO(), node1PK, node5PK, 0, 100, 5) require.NoError(t, err) require.Len(t, routes, 3) - routes, err = g.Shortest(context.TODO(), node1PK, node5PK, 0, 2, 5) + routes, err = g.GetRoute(context.TODO(), node1PK, node5PK, 0, 2, 5) require.NoError(t, err) require.Len(t, routes, 2) - routes, err = g.Shortest(context.TODO(), node1PK, node5PK, 0, 100, 1) + routes, err = g.GetRoute(context.TODO(), node1PK, node5PK, 0, 100, 1) require.NoError(t, err) require.Len(t, routes, 1) } -func TestDijkstraRoute(t *testing.T) { +func TestFinderRoute(t *testing.T) { node1PK, node2PK, node3PK, node4PK, node5PK := generateNodesPK(t) m := newMockStore() @@ -49,7 +49,7 @@ func TestDijkstraRoute(t *testing.T) { g, err := NewGraph(context.TODO(), m, node1PK) require.NoError(t, err) - routes, err := g.Shortest(context.TODO(), node1PK, node5PK, 0, 100, 1) + routes, err := g.GetRoute(context.TODO(), node1PK, node5PK, 0, 100, 1) require.NoError(t, err) require.Len(t, routes, 1) require.Equal(t, routes[0].Hops[0].From, node1PK) @@ -76,7 +76,7 @@ func TestNoRoutesFromNoPathWithRootNodes(t *testing.T) { c, f := context.WithTimeout(context.Background(), 2*time.Second) defer f() - r, err := g.Shortest(c, node1PK, node3PK, 0, 100, 5) + r, err := g.GetRoute(c, node1PK, node3PK, 0, 100, 5) require.NoError(t, err) fmt.Println(r) } diff --git a/pkg/route-finder/store/graph_test.go b/pkg/route-finder/store/graph_test.go index 8a936c70..62e2bb7e 100644 --- a/pkg/route-finder/store/graph_test.go +++ b/pkg/route-finder/store/graph_test.go @@ -46,7 +46,7 @@ func (m *mockStore) GetTransportsByEdge(_ context.Context, edgePK cipher.PubKey) func (m *mockStore) GetNumberOfTransports(context.Context) (map[network.Type]int, error) { return nil, nil } -func (m *mockStore) GetAllTransports(context.Context) ([]*transport.Entry, error) { +func (m *mockStore) GetAllTransports(context.Context, bool) ([]*transport.Entry, error) { return nil, nil } func (m *mockStore) Close() {} diff --git a/pkg/route-finder/store/priority_queue.go b/pkg/route-finder/store/priority_queue.go deleted file mode 100644 index 623e449e..00000000 --- a/pkg/route-finder/store/priority_queue.go +++ /dev/null @@ -1,48 +0,0 @@ -package store - -import ( - "container/heap" -) - -// implementation from https://rosettacode.org/wiki/Dijkstra%27s_algorithm#Go -// A priorityQueue implements heap.Interface and holds Items. -type priorityQueue struct { - items []*vertex - // value to index - m map[*vertex]int - // value to priority - pr map[*vertex]int -} - -func (pq *priorityQueue) Len() int { return len(pq.items) } -func (pq *priorityQueue) Less(i, j int) bool { return pq.pr[pq.items[i]] < pq.pr[pq.items[j]] } -func (pq *priorityQueue) Swap(i, j int) { - pq.items[i], pq.items[j] = pq.items[j], pq.items[i] - pq.m[pq.items[i]] = i - pq.m[pq.items[j]] = j -} - -func (pq *priorityQueue) Push(x interface{}) { - n := len(pq.items) - item := x.(*vertex) - pq.m[item] = n - pq.items = append(pq.items, item) -} -func (pq *priorityQueue) Pop() interface{} { - old := pq.items - n := len(old) - item := old[n-1] - pq.m[item] = -1 - pq.items = old[0 : n-1] - return item -} - -// update modifies the priority of an item in the queue. -func (pq *priorityQueue) update(item *vertex, priority int) { - pq.pr[item] = priority - heap.Fix(pq, pq.m[item]) -} -func (pq *priorityQueue) addWithPriority(item *vertex, priority int) { - heap.Push(pq, item) - pq.update(item, priority) -} diff --git a/pkg/transport-discovery/api/api_test.go b/pkg/transport-discovery/api/api_test.go index af09f2c5..8544b4cc 100644 --- a/pkg/transport-discovery/api/api_test.go +++ b/pkg/transport-discovery/api/api_test.go @@ -315,7 +315,7 @@ func TestGETAllTransports(t *testing.T) { require.Len(t, resp, 2) t.Run("Persistence", func(t *testing.T) { - found, err := mock.GetAllTransports(ctx) + found, err := mock.GetAllTransports(ctx, true) require.NoError(t, err) for i, f := range found { if f.ID == resp[i].ID { diff --git a/pkg/transport-discovery/api/endpoints.go b/pkg/transport-discovery/api/endpoints.go index b722190d..f71b67f3 100644 --- a/pkg/transport-discovery/api/endpoints.go +++ b/pkg/transport-discovery/api/endpoints.go @@ -89,8 +89,13 @@ func (api *API) getTransportByEdge(w http.ResponseWriter, r *http.Request) { } func (api *API) getAllTransports(w http.ResponseWriter, r *http.Request) { - - entries, err := api.store.GetAllTransports(r.Context()) + selfTransports := true + query := r.URL.Query() + selfTransportsParam := query.Get("selfTransports") + if selfTransportsParam == "hide" { + selfTransports = false + } + entries, err := api.store.GetAllTransports(r.Context(), selfTransports) if err != nil { if err != store.ErrTransportNotFound { api.log(r).WithError(err).Error("Error getting transports") diff --git a/pkg/transport-discovery/store/memory_store.go b/pkg/transport-discovery/store/memory_store.go index 9dd82159..810c4627 100644 --- a/pkg/transport-discovery/store/memory_store.go +++ b/pkg/transport-discovery/store/memory_store.go @@ -116,11 +116,16 @@ func (s *memStore) GetNumberOfTransports(context.Context) (map[network.Type]int, return response, nil } -func (s *memStore) GetAllTransports(context.Context) ([]*transport.Entry, error) { +func (s *memStore) GetAllTransports(_ context.Context, selfTransports bool) ([]*transport.Entry, error) { s.mu.Lock() defer s.mu.Unlock() var response []*transport.Entry for _, entry := range s.transports { + if !selfTransports { + if entry.Edges[0] == entry.Edges[1] { + continue + } + } response = append(response, entry) } return response, nil diff --git a/pkg/transport-discovery/store/postgres_store.go b/pkg/transport-discovery/store/postgres_store.go index 7d0fae7c..6c4f416e 100644 --- a/pkg/transport-discovery/store/postgres_store.go +++ b/pkg/transport-discovery/store/postgres_store.go @@ -102,7 +102,7 @@ func (s *postgresStore) GetNumberOfTransports(context.Context) (map[network.Type return response, nil } -func (s *postgresStore) GetAllTransports(context.Context) ([]*transport.Entry, error) { +func (s *postgresStore) GetAllTransports(_ context.Context, selfTransports bool) ([]*transport.Entry, error) { var tpRecords []Transport if err := s.client.Find(&tpRecords).Error; err != nil { return nil, ErrTransportNotFound @@ -115,6 +115,11 @@ func (s *postgresStore) GetAllTransports(context.Context) ([]*transport.Entry, e if err != nil { return nil, err } + if !selfTransports { + if entry.Edges[0] == entry.Edges[1] { + continue + } + } entries = append(entries, &entry) } diff --git a/pkg/transport-discovery/store/store.go b/pkg/transport-discovery/store/store.go index c4402e1e..01ae9203 100644 --- a/pkg/transport-discovery/store/store.go +++ b/pkg/transport-discovery/store/store.go @@ -35,7 +35,7 @@ type TransportStore interface { GetTransportByID(context.Context, uuid.UUID) (*transport.Entry, error) GetTransportsByEdge(context.Context, cipher.PubKey) ([]*transport.Entry, error) GetNumberOfTransports(context.Context) (map[network.Type]int, error) - GetAllTransports(context.Context) ([]*transport.Entry, error) + GetAllTransports(context.Context, bool) ([]*transport.Entry, error) Close() }