Skip to content

Commit

Permalink
update hops away when packet is heard
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Nov 17, 2024
1 parent 615dbba commit 9ca2186
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/components/nodes/NodesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@
<div>{{ getNodeLongName(node.num) }}</div>
<div class="text-sm text-gray-500">

<!-- hops away -->
<span v-if="node.hopsAway === 0">Direct Connection</span>
<span v-else-if="node.hopsAway === 1">1 Hop Away</span>
<span v-else>{{ node.hopsAway }} Hops Away</span>
<!-- our node info -->
<div v-if="node.num === GlobalState.myNodeId">
You are connected to this node
</div>

<!-- last heard -->
<span v-if="node.lastHeard"> • heard {{ formatUnixSecondsAgo(node.lastHeard) }}</span>
<!-- other node info -->
<div v-else>

<!-- hops away -->
<span v-if="node.hopsAway === -1">Direct Connection</span>
<span v-else-if="node.hopsAway === 0">Direct Connection</span>
<span v-else-if="node.hopsAway === 1">1 Hop Away</span>
<span v-else>{{ node.hopsAway }} Hops Away</span>

<!-- last heard -->
<span v-if="node.lastHeard"> • heard {{ formatUnixSecondsAgo(node.lastHeard) }}</span>

</div>

</div>
</div>
Expand All @@ -39,6 +50,7 @@
import NodeUtils from "../../js/NodeUtils.js";
import moment from "moment";
import NodeIcon from "./NodeIcon.vue";
import GlobalState from "../../js/GlobalState.js";
export default {
name: 'NodesList',
Expand Down Expand Up @@ -69,6 +81,9 @@ export default {
},
},
computed: {
GlobalState() {
return GlobalState;
},
orderedNodes() {
return this.nodesOrderedByLastHeard;
},
Expand Down
8 changes: 7 additions & 1 deletion src/js/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,21 @@ class Connection {
const rxTime = data.rxTime;
const fromNodeId = data.from;

// determine hops away
const hopStart = data.hopStart;
const hopLimit = data.hopLimit;
const hopsAway = (hopStart === 0 || hopLimit > hopStart) ? -1 : hopStart - hopLimit;

// find node by id or do nothing
const node = GlobalState.nodesById[fromNodeId];
if(!node){
return;
}

// update last heard on node we received packet from
// update last heard and hops away for the node we received packet from
console.log(`updating last heard for node ${fromNodeId} to ${rxTime}`);
node.lastHeard = rxTime;
node.hopsAway = hopsAway;

});

Expand Down

0 comments on commit 9ca2186

Please sign in to comment.