Skip to content

Commit

Permalink
Merge pull request #91 from mrpalide/fix/solve-minhop-issue
Browse files Browse the repository at this point in the history
Fix minhop issue
  • Loading branch information
mrpalide authored Jan 26, 2025
2 parents f0b7a58 + facd003 commit 0f29312
Show file tree
Hide file tree
Showing 23 changed files with 215 additions and 250 deletions.
5 changes: 4 additions & 1 deletion cmd/route-finder/README.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down Expand Up @@ -27,4 +30,4 @@ Body:
"max_hops": 0
}
}
```
```
3 changes: 2 additions & 1 deletion docker/config/dmsg-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dmsg": {
"discovery": "http://dmsg-discovery:9090",
"sessions_count": 1,
"servers": []
"servers": [],
"servers_type": "all"
},
"transport": {
"discovery": "http://transport-discovery:9091",
Expand Down
3 changes: 2 additions & 1 deletion docker/config/network-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dmsg": {
"discovery": "http://dmsg-discovery:9090",
"sessions_count": 1,
"servers": []
"servers": [],
"servers_type": "all"
},
"transport": {
"discovery": "http://transport-discovery:9091",
Expand Down
3 changes: 2 additions & 1 deletion docker/config/public-visor-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dmsg": {
"discovery": "http://dmsg-discovery:9090",
"sessions_count": 1,
"servers": []
"servers": [],
"servers_type": "all"
},
"transport": {
"discovery": "http://transport-discovery:9091",
Expand Down
3 changes: 2 additions & 1 deletion docker/config/skysocks-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dmsg": {
"discovery": "http://dmsg-discovery:9090",
"sessions_count": 1,
"servers": []
"servers": [],
"servers_type": "all"
},
"transport": {
"discovery": "http://transport-discovery:9091",
Expand Down
3 changes: 2 additions & 1 deletion docker/config/tpd-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dmsg": {
"discovery": "http://dmsg-discovery:9090",
"sessions_count": 1,
"servers": []
"servers": [],
"servers_type": "all"
},
"transport": {
"discovery": "http://transport-discovery:9091",
Expand Down
3 changes: 2 additions & 1 deletion docker/config/vpn-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dmsg": {
"discovery": "http://dmsg-discovery:9090",
"sessions_count": 1,
"servers": []
"servers": [],
"servers_type": "all"
},
"transport": {
"discovery": "http://transport-discovery:9091",
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docker/images/service-discovery/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/integration/visorA.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@
"stun_servers": null,
"shutdown_timeout": "30s",
"restart_check_delay": "1s",
"is_public": true,
"is_public": false,
"persistent_transports": null
}
18 changes: 14 additions & 4 deletions docker/integration/visorC.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dmsg": {
"discovery": "http://dmsg-discovery:9090",
"sessions_count": 1,
"servers": []
"servers": [],
"servers_type": "all"
},
"dmsgpty": {
"dmsg_port": 22,
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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
}
28 changes: 23 additions & 5 deletions pkg/node-visualizer/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
})
}

Expand All @@ -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,
})
}
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/route-finder/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 0f29312

Please sign in to comment.