// Copyright 2016 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// Contains all the wrappers from the accounts package to support client side enode
// management on mobile platforms.

package geth

import (
	"errors"

	"github.com/tangerine-network/go-tangerine/p2p/discv5"
)

// Enode represents a host on the network.
type Enode struct {
	node *discv5.Node
}

// NewEnode parses a node designator.
//
// There are two basic forms of node designators
//   - incomplete nodes, which only have the public key (node ID)
//   - complete nodes, which contain the public key and IP/Port information
//
// For incomplete nodes, the designator must look like one of these
//
//    enode://<hex node id>
//    <hex node id>
//
// 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
// only be given as an IP address, DNS domain names are not allowed.
// The port in the host name section is the TCP listening port. If the
// TCP and UDP (discovery) ports differ, the UDP port is specified as
// query parameter "discport".
//
// In the following example, the node URL describes
// a node with IP address 10.3.58.6, TCP listening port 30303
// and UDP discovery port 30301.
//
//    enode://<hex node id>@10.3.58.6:30303?discport=30301
func NewEnode(rawurl string) (enode *Enode, _ error) {
	node, err := discv5.ParseNode(rawurl)
	if err != nil {
		return nil, err
	}
	return &Enode{node}, nil
}

// Enodes represents a slice of accounts.
type Enodes struct{ nodes []*discv5.Node }

// NewEnodes creates a slice of uninitialized enodes.
func NewEnodes(size int) *Enodes {
	return &Enodes{
		nodes: make([]*discv5.Node, size),
	}
}

// NewEnodesEmpty creates an empty slice of Enode values.
func NewEnodesEmpty() *Enodes {
	return NewEnodes(0)
}

// Size returns the number of enodes in the slice.
func (e *Enodes) Size() int {
	return len(e.nodes)
}

// Get returns the enode at the given index from the slice.
func (e *Enodes) Get(index int) (enode *Enode, _ error) {
	if index < 0 || index >= len(e.nodes) {
		return nil, errors.New("index out of bounds")
	}
	return &Enode{e.nodes[index]}, nil
}

// Set sets the enode at the given index in the slice.
func (e *Enodes) Set(index int, enode *Enode) error {
	if index < 0 || index >= len(e.nodes) {
		return errors.New("index out of bounds")
	}
	e.nodes[index] = enode.node
	return nil
}

// Append adds a new enode element to the end of the slice.
func (e *Enodes) Append(enode *Enode) {
	e.nodes = append(e.nodes, enode.node)
}
option>
<option value='branches/2014Q3'>branches/2014Q3</option>
<option value='branches/2014Q4'>branches/2014Q4</option>
<option value='branches/2015Q1'>branches/2015Q1</option>
<option value='branches/2015Q2'>branches/2015Q2</option>
<option value='branches/2015Q3'>branches/2015Q3</option>
<option value='branches/2015Q4'>branches/2015Q4</option>
<option value='branches/2016Q1'>branches/2016Q1</option>
<option value='branches/2016Q2'>branches/2016Q2</option>
<option value='branches/2016Q3'>branches/2016Q3</option>
<option value='branches/2016Q4'>branches/2016Q4</option>
<option value='branches/2017Q1'>branches/2017Q1</option>
<option value='branches/2017Q2'>branches/2017Q2</option>
<option value='branches/2017Q3'>branches/2017Q3</option>
<option value='branches/2017Q4'>branches/2017Q4</option>
<option value='branches/2018Q1'>branches/2018Q1</option>
<option value='branches/2018Q2'>branches/2018Q2</option>
<option value='branches/2018Q3'>branches/2018Q3</option>
<option value='branches/2018Q4'>branches/2018Q4</option>
<option value='branches/2019Q1'>branches/2019Q1</option>
<option value='branches/2019Q2'>branches/2019Q2</option>
<option value='branches/2019Q3'>branches/2019Q3</option>
<option value='branches/2019Q4'>branches/2019Q4</option>
<option value='branches/2020Q1'>branches/2020Q1</option>
<option value='branches/2020Q2'>branches/2020Q2</option>
<option value='branches/2020Q3'>branches/2020Q3</option>
<option value='branches/2020Q4'>branches/2020Q4</option>
<option value='branches/2021Q1'>branches/2021Q1</option>
<option value='branches/RELEASE_8_4_0'>branches/RELEASE_8_4_0</option>
<option value='branches/RELENG_2_1_0'>branches/RELENG_2_1_0</option>
<option value='branches/RELENG_2_2'>branches/RELENG_2_2</option>
<option value='branches/RELENG_9_1_0'>branches/RELENG_9_1_0</option>
<option value='branches/RELENG_9_2_0'>branches/RELENG_9_2_0</option>
<option value='dependabot/npm_and_yarn/devel/electron4/files/eslint-utils-1.4.3'>dependabot/npm_and_yarn/devel/electron4/files/eslint-utils-1.4.3</option>
<option value='dependabot/npm_and_yarn/devel/electron4/files/lodash-4.17.15'>dependabot/npm_and_yarn/devel/electron4/files/lodash-4.17.15</option>
<option value='dependabot/npm_and_yarn/devel/electron4/files/lodash.merge-4.6.2'>dependabot/npm_and_yarn/devel/electron4/files/lodash.merge-4.6.2</option>
<option value='dependabot/npm_and_yarn/devel/electron4/files/lodash.template-4.5.0'>dependabot/npm_and_yarn/devel/electron4/files/lodash.template-4.5.0</option>
<option value='dependabot/npm_and_yarn/devel/electron4/files/minimist-1.2.2'>dependabot/npm_and_yarn/devel/electron4/files/minimist-1.2.2</option>
<option value='dependabot/npm_and_yarn/devel/electron4/files/mixin-deep-1.3.2'>dependabot/npm_and_yarn/devel/electron4/files/mixin-deep-1.3.2</option>
<option value='main' selected='selected'>main</option>
<option value='master'>master</option>
<option value='svn_head'>svn_head</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>FreeBSD Ports (https://github.com/freebsd/freebsd-ports)</td><td class='sub right'></td></tr></table>
<table class='tabs'><tr><td>
<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/about/'>about</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/'>summary</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/refs/?id=d3a83f3dbe86dc3a11c51d9c5779f31a397cf708'>refs</a><a class='active' href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/security/pear-Horde_Secret'>log</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/tree/security/pear-Horde_Secret?id=d3a83f3dbe86dc3a11c51d9c5779f31a397cf708'>tree</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=d3a83f3dbe86dc3a11c51d9c5779f31a397cf708'>commit</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/diff/security/pear-Horde_Secret?id=d3a83f3dbe86dc3a11c51d9c5779f31a397cf708'>diff</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/stats/security/pear-Horde_Secret'>stats</a></td><td class='form'><form class='right' method='get' action='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/security/pear-Horde_Secret'>
<input type='hidden' name='id' value='d3a83f3dbe86dc3a11c51d9c5779f31a397cf708'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/?id=d3a83f3dbe86dc3a11c51d9c5779f31a397cf708'>root</a>/<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/security?id=d3a83f3dbe86dc3a11c51d9c5779f31a397cf708'>security</a>/<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/security/pear-Horde_Secret?id=d3a83f3dbe86dc3a11c51d9c5779f31a397cf708'>pear-Horde_Secret</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th></th><th class='left'>Commit message (<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/security/pear-Horde_Secret?id=d3a83f3dbe86dc3a11c51d9c5779f31a397cf708&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Age</th><th class='left'>Files</th><th class='left'>Lines</th></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=fb16dfecae4a6efac9f3a78e0b759fb7a3c53de4'>Remove WWW entries moved into port Makefiles</a></td><td>Stefan Eßer</td><td><span title='2022-09-08 05:58:51 +0800'>2022-09-08</span></td><td>1</td><td><span class='deletions'>-2</span>/<span class='insertions'>+0</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=b7f05445c00f2625aa19b4154ebcbce5ed2daa52'>Add WWW entries to port Makefiles</a></td><td>Stefan Eßer</td><td><span title='2022-09-08 05:10:59 +0800'>2022-09-08</span></td><td>1</td><td><span class='deletions'>-0</span>/<span class='insertions'>+1</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=857c05f8674c5f4c990f49f9d0fb7034ebd340fe'>security: remove 'Created by' lines</a></td><td>Tobias C. Berner</td><td><span title='2022-07-20 22:22:56 +0800'>2022-07-20</span></td><td>1</td><td><span class='deletions'>-2</span>/<span class='insertions'>+0</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=29a56aa2eb28cb0574ea34b9ad41d850909bf2ae'>*/*: Add CPE information for horde ports</a></td><td>Bernhard Froehlich</td><td><span title='2021-10-08 15:09:48 +0800'>2021-10-08</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+1</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=305f148f482daf30dcf728039d03d019f88344eb'>Remove # $FreeBSD$ from Makefiles.</a></td><td>Mathieu Arnold</td><td><span title='2021-04-06 22:31:07 +0800'>2021-04-06</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+0</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=77baedc828998509aa22424356a907d80799d6b8'>security: Add missing USES={gnome,php}</a></td><td>Tobias Kortkamp</td><td><span title='2019-11-08 21:17:00 +0800'>2019-11-08</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+1</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=817ca149ff7d370c7523337fd8c2ac0ea9d8e64a'>Horde package update:</a></td><td>Martin Matuska</td><td><span title='2016-02-03 06:56:26 +0800'>2016-02-03</span></td><td>2</td><td><span class='deletions'>-3</span>/<span class='insertions'>+3</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=f927ae941d942a872d36aa8e4f8c0590a265bf6c'>Horde package update:</a></td><td>Martin Matuska</td><td><span title='2015-10-23 00:00:30 +0800'>2015-10-23</span></td><td>2</td><td><span class='deletions'>-3</span>/<span class='insertions'>+3</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=eb8748bedad607ac907ca3545ad41d6931f779fc'>Remove trailing whitespace from Makefiles, M-X.</a></td><td>Jimmy Olgeni</td><td><span title='2015-10-08 23:12:22 +0800'>2015-10-08</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+1</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=3cae31f88b46275a77bd53c045e5cdf0d55433ec'>Horde package update:</a></td><td>Martin Matuska</td><td><span title='2014-10-30 06:12:34 +0800'>2014-10-30</span></td><td>2</td><td><span class='deletions'>-3</span>/<span class='insertions'>+3</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/security/pear-Horde_Secret?id=1446608ec7d77c3b6208b159208122f133264296'>Convert to USES=horde</a></td><td>Baptiste Daroussin</td><td><span title='2014-10-01 06:14:59 +0800'>2014-10-01</span></td><td>1</td><td><span class='deletions'>-3</span>/<span class='insertions'>+2</span></td></tr>