|
@@ -54,8 +54,8 @@ func MustParseV4(rawurl string) *Node {
|
|
|
//
|
|
//
|
|
|
// For incomplete nodes, the designator must look like one of these
|
|
// For incomplete nodes, the designator must look like one of these
|
|
|
//
|
|
//
|
|
|
-// enode://<hex node id>
|
|
|
|
|
-// <hex node id>
|
|
|
|
|
|
|
+// enode://<hex node id>
|
|
|
|
|
+// <hex node id>
|
|
|
//
|
|
//
|
|
|
// For complete nodes, the node ID is encoded in the username portion
|
|
// For complete nodes, the node ID is encoded in the username portion
|
|
|
// of the URL, separated from the host by an @ sign. The hostname can
|
|
// of the URL, separated from the host by an @ sign. The hostname can
|
|
@@ -68,7 +68,7 @@ func MustParseV4(rawurl string) *Node {
|
|
|
// a node with IP address 10.3.58.6, TCP listening port 30303
|
|
// a node with IP address 10.3.58.6, TCP listening port 30303
|
|
|
// and UDP discovery port 30301.
|
|
// and UDP discovery port 30301.
|
|
|
//
|
|
//
|
|
|
-// enode://<hex node id>@10.3.58.6:30303?discport=30301
|
|
|
|
|
|
|
+// enode://<hex node id>@10.3.58.6:30303?discport=30301
|
|
|
func ParseV4(rawurl string) (*Node, error) {
|
|
func ParseV4(rawurl string) (*Node, error) {
|
|
|
if m := incompleteNodeURL.FindStringSubmatch(rawurl); m != nil {
|
|
if m := incompleteNodeURL.FindStringSubmatch(rawurl); m != nil {
|
|
|
id, err := parsePubkey(m[1])
|
|
id, err := parsePubkey(m[1])
|
|
@@ -80,6 +80,17 @@ func ParseV4(rawurl string) (*Node, error) {
|
|
|
return parseComplete(rawurl)
|
|
return parseComplete(rawurl)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func NodeFromConn(pubkey *ecdsa.PublicKey, conn net.Conn) *Node {
|
|
|
|
|
+ var ip net.IP
|
|
|
|
|
+ var port int
|
|
|
|
|
+ if tcp, ok := conn.RemoteAddr().(*net.TCPAddr); ok {
|
|
|
|
|
+ ip = tcp.IP
|
|
|
|
|
+ port = tcp.Port
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return NewV4(pubkey, ip, port, port)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// NewV4 creates a node from discovery v4 node information. The record
|
|
// NewV4 creates a node from discovery v4 node information. The record
|
|
|
// contained in the node has a zero-length signature.
|
|
// contained in the node has a zero-length signature.
|
|
|
func NewV4(pubkey *ecdsa.PublicKey, ip net.IP, tcp, udp int) *Node {
|
|
func NewV4(pubkey *ecdsa.PublicKey, ip net.IP, tcp, udp int) *Node {
|