github.com/n1ghtfa1l/go-vnt@v0.6.4-alpha.6/mobile/discover.go (about) 1 // Copyright 2016 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Contains all the wrappers from the accounts package to support client side vnode 18 // management on mobile platforms. 19 20 package gvnt 21 22 // import ( 23 // "errors" 24 // ) 25 26 // // Vnode represents a host on the network. 27 // type Vnode struct { 28 // node *discv5.Node 29 // } 30 31 // // NewEnode parses a node designator. 32 // // 33 // // There are two basic forms of node designators 34 // // - incomplete nodes, which only have the public key (node ID) 35 // // - complete nodes, which contain the public key and IP/Port information 36 // // 37 // // For incomplete nodes, the designator must look like one of these 38 // // 39 // // vnode://<hex node id> 40 // // <hex node id> 41 // // 42 // // For complete nodes, the node ID is encoded in the username portion 43 // // of the URL, separated from the host by an @ sign. The hostname can 44 // // only be given as an IP address, DNS domain names are not allowed. 45 // // The port in the host name section is the TCP listening port. If the 46 // // TCP and UDP (discovery) ports differ, the UDP port is specified as 47 // // query parameter "discport". 48 // // 49 // // In the following example, the node URL describes 50 // // a node with IP address 10.3.58.6, TCP listening port 30303 51 // // and UDP discovery port 30301. 52 // // 53 // // vnode://<hex node id>@10.3.58.6:30303?discport=30301 54 // func NewEnode(rawurl string) (vnode *Vnode, _ error) { 55 // node, err := discv5.ParseNode(rawurl) 56 // if err != nil { 57 // return nil, err 58 // } 59 // return &Vnode{node}, nil 60 // } 61 62 // // Enodes represents a slice of accounts. 63 // type Enodes struct{ nodes []*discv5.Node } 64 65 // // NewEnodes creates a slice of uninitialized enodes. 66 // func NewEnodes(size int) *Enodes { 67 // return &Enodes{ 68 // nodes: make([]*discv5.Node, size), 69 // } 70 // } 71 72 // // NewEnodesEmpty creates an empty slice of Vnode values. 73 // func NewEnodesEmpty() *Enodes { 74 // return NewEnodes(0) 75 // } 76 77 // // Size returns the number of enodes in the slice. 78 // func (e *Enodes) Size() int { 79 // return len(e.nodes) 80 // } 81 82 // // Get returns the vnode at the given index from the slice. 83 // func (e *Enodes) Get(index int) (vnode *Vnode, _ error) { 84 // if index < 0 || index >= len(e.nodes) { 85 // return nil, errors.New("index out of bounds") 86 // } 87 // return &Vnode{e.nodes[index]}, nil 88 // } 89 90 // // Set sets the vnode at the given index in the slice. 91 // func (e *Enodes) Set(index int, vnode *Vnode) error { 92 // if index < 0 || index >= len(e.nodes) { 93 // return errors.New("index out of bounds") 94 // } 95 // e.nodes[index] = vnode.node 96 // return nil 97 // } 98 99 // // Append adds a new vnode element to the end of the slice. 100 // func (e *Enodes) Append(vnode *Vnode) { 101 // e.nodes = append(e.nodes, vnode.node) 102 // }