Skip to content

Commit 1a4b945

Browse files
authored
Merge pull request ethereum#98 from holisticode/link_distance
Link distance
2 parents 56679df + 527d12c commit 1a4b945

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

p2p/simulations/network.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/ethereum/go-ethereum/p2p"
3838
"github.com/ethereum/go-ethereum/p2p/discover"
3939
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
40+
"github.com/ethereum/go-ethereum/pot"
4041
"github.com/ethereum/go-ethereum/rpc"
4142
)
4243

@@ -166,8 +167,9 @@ type Conn struct {
166167
Up bool `json:"up"`
167168
// reverse is false by default (One dialled/dropped the Other)
168169
Reverse bool `json:"reverse"`
169-
// Info
170-
// average throughput, recent average throughput etc
170+
// A scalar distance value denoting how "far" Other is from One (Kademlia table)
171+
Distance int `json:"distance"`
172+
// indicates if a ControlEvent has already been fired for this connection
171173
controlFired bool
172174
}
173175

@@ -242,11 +244,13 @@ func (self *Network) newConn(oneID, otherID discover.NodeID) (*Conn, error) {
242244
if other == nil {
243245
return nil, fmt.Errorf("other %v does not exist", other)
244246
}
247+
distance, _ := pot.NewBytesVal(one.Addr(), nil).PO(pot.NewBytesVal(other.Addr(), nil), 0)
245248
return &Conn{
246-
One: oneID,
247-
Other: otherID,
248-
one: one,
249-
other: other,
249+
One: oneID,
250+
Other: otherID,
251+
one: one,
252+
other: other,
253+
Distance: distance,
250254
}, nil
251255
}
252256

0 commit comments

Comments
 (0)