aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/discover/node.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-12-07 19:06:49 +0800
committerFelix Lange <fjl@twurst.com>2015-12-18 06:38:54 +0800
commit04c6369a09baa5267a01713663f7c1cbb08896c9 (patch)
tree4650aaf3537e6fdab784e180f5efc9070a961cf9 /p2p/discover/node.go
parentd1f507b7f16e359dc2773195edb72a22357e5424 (diff)
downloaddexon-04c6369a09baa5267a01713663f7c1cbb08896c9.tar
dexon-04c6369a09baa5267a01713663f7c1cbb08896c9.tar.gz
dexon-04c6369a09baa5267a01713663f7c1cbb08896c9.tar.bz2
dexon-04c6369a09baa5267a01713663f7c1cbb08896c9.tar.lz
dexon-04c6369a09baa5267a01713663f7c1cbb08896c9.tar.xz
dexon-04c6369a09baa5267a01713663f7c1cbb08896c9.tar.zst
dexon-04c6369a09baa5267a01713663f7c1cbb08896c9.zip
p2p, p2p/discover: track bootstrap state in p2p/discover
This change simplifies the dial scheduling logic because it no longer needs to track whether the discovery table has been bootstrapped.
Diffstat (limited to 'p2p/discover/node.go')
-rw-r--r--p2p/discover/node.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/p2p/discover/node.go b/p2p/discover/node.go
index fac493f01..c4a3b5011 100644
--- a/p2p/discover/node.go
+++ b/p2p/discover/node.go
@@ -80,6 +80,24 @@ func (n *Node) Incomplete() bool {
return n.IP == nil
}
+// checks whether n is a valid complete node.
+func (n *Node) validateComplete() error {
+ if n.Incomplete() {
+ return errors.New("incomplete node")
+ }
+ if n.UDP == 0 {
+ return errors.New("missing UDP port")
+ }
+ if n.TCP == 0 {
+ return errors.New("missing TCP port")
+ }
+ if n.IP.IsMulticast() || n.IP.IsUnspecified() {
+ return errors.New("invalid IP (multicast/unspecified)")
+ }
+ _, err := n.ID.Pubkey() // validate the key (on curve, etc.)
+ return err
+}
+
// The string representation of a Node is a URL.
// Please see ParseNode for a description of the format.
func (n *Node) String() string {
@@ -249,7 +267,7 @@ func (id NodeID) Pubkey() (*ecdsa.PublicKey, error) {
p.X.SetBytes(id[:half])
p.Y.SetBytes(id[half:])
if !p.Curve.IsOnCurve(p.X, p.Y) {
- return nil, errors.New("not a point on the S256 curve")
+ return nil, errors.New("id is invalid secp256k1 curve point")
}
return p, nil
}