Merge pull request #98 from holisticode/link_distance

Link distance
This commit is contained in:
Viktor Trón 2017-05-29 23:47:21 -04:00 committed by GitHub
commit 1a4b945bff

View file

@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/simulations/adapters" "github.com/ethereum/go-ethereum/p2p/simulations/adapters"
"github.com/ethereum/go-ethereum/pot"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
@ -166,8 +167,9 @@ type Conn struct {
Up bool `json:"up"` Up bool `json:"up"`
// reverse is false by default (One dialled/dropped the Other) // reverse is false by default (One dialled/dropped the Other)
Reverse bool `json:"reverse"` Reverse bool `json:"reverse"`
// Info // A scalar distance value denoting how "far" Other is from One (Kademlia table)
// average throughput, recent average throughput etc Distance int `json:"distance"`
// indicates if a ControlEvent has already been fired for this connection
controlFired bool controlFired bool
} }
@ -242,11 +244,13 @@ func (self *Network) newConn(oneID, otherID discover.NodeID) (*Conn, error) {
if other == nil { if other == nil {
return nil, fmt.Errorf("other %v does not exist", other) return nil, fmt.Errorf("other %v does not exist", other)
} }
distance, _ := pot.NewBytesVal(one.Addr(), nil).PO(pot.NewBytesVal(other.Addr(), nil), 0)
return &Conn{ return &Conn{
One: oneID, One: oneID,
Other: otherID, Other: otherID,
one: one, one: one,
other: other, other: other,
Distance: distance,
}, nil }, nil
} }