Constructor
new HostList(options)
Create a host list.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- Source:
Members
(static, constant) HORIZON_DAYS :Number
Number of days before considering an address stale.
Type:
- Number
- Default Value:
- 30
- Source:
(static, constant) MAX_FAILURES :Number
Maximum number of failures allowed before considering an address stale.
Type:
- Number
- Default Value:
- 10
- Source:
(static, constant) MAX_REFS :Number
Maximum number of references in fresh buckets.
Type:
- Number
- Default Value:
- 8
- Source:
(static, constant) MIN_FAIL_DAYS :Number
Number of days after reaching MAX_FAILURES to consider an address stale.
Type:
- Number
- Default Value:
- 7
- Source:
(static, constant) RETRIES :Number
Number of retries (without success) before considering an address stale.
Type:
- Number
- Default Value:
- 3
- Source:
(static) scores :Number
Local address scores.
Type:
- Number
Properties:
Name | Type | Description |
---|---|---|
NONE |
Number | |
IF |
Number | |
BIND |
Number | |
UPNP |
Number | |
DNS |
Number | |
MANUAL |
Number | |
MAX |
Number |
- Default Value:
{"NONE":0,"IF":1,"BIND":2,"UPNP":3,"DNS":3,"MANUAL":4,"MAX":5}
- Source:
(static, constant) VERSION :Number
Serialization version.
Type:
- Number
- Source:
Methods
(static) fromJSON(options, json) → {HostList}
Instantiate host list from json object.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | |
json |
Object |
- Source:
Returns:
- Type
- HostList
add(addr, srcnullable) → {Boolean}
Add host to host list.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
addr |
NetAddress | ||
src |
NetAddress |
<nullable> |
- Source:
Returns:
- Type
- Boolean
addLocal(host, port, score) → {Boolean}
Add a local address.
Parameters:
Name | Type | Description |
---|---|---|
host |
String | |
port |
Number | |
score |
Number |
- Source:
Returns:
- Type
- Boolean
addNode(host) → {NetAddress}
Add a priority node.
Parameters:
Name | Type | Description |
---|---|---|
host |
String |
- Source:
Returns:
- Type
- NetAddress
addSeed(host)
Add a preferred seed.
Parameters:
Name | Type | Description |
---|---|---|
host |
String |
- Source:
ban(host)
Mark a peer as banned.
Parameters:
Name | Type | Description |
---|---|---|
host |
String |
- Source:
clearBanned()
Clear banned hosts.
- Source:
(async) close() → {Promise}
Close hostlist.
- Source:
Returns:
- Type
- Promise
(async) discoverNodes() → {Promise}
Discover hosts from nodes.
- Source:
Returns:
- Type
- Promise
(async) discoverSeeds() → {Promise}
Discover hosts from seeds.
- Source:
Returns:
- Type
- Promise
evictFresh(bucket)
Evict a host from fresh bucket.
Parameters:
Name | Type | Description |
---|---|---|
bucket |
Map |
- Source:
evictUsed(bucket)
Pick used for eviction.
Parameters:
Name | Type | Description |
---|---|---|
bucket |
List |
- Source:
(async) flush() → {Promise}
Flush addrs to hosts file.
- Source:
Returns:
- Type
- Promise
(private) freshBucket(entry) → {Map}
Get fresh bucket for host.
Parameters:
Name | Type | Description |
---|---|---|
entry |
HostEntry |
- Source:
Returns:
- Type
- Map
(private) fromJSON(json) → {HostList}
Inject properties from json object.
Parameters:
Name | Type | Description |
---|---|---|
json |
Object |
- Source:
Returns:
- Type
- HostList
getHost() → {HostEntry}
Allocate a new host.
- Source:
Returns:
- Type
- HostEntry
getLocal(srcnullable) → {NetAddress}
Get local address based on reachability.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
src |
NetAddress |
<nullable> |
- Source:
Returns:
- Type
- NetAddress
(private) init()
Initialize list.
- Source:
injectSeeds() → {Promise}
Read and initialize from hosts file.
- Source:
Returns:
- Type
- Promise
isBanned(host) → {Boolean}
Test whether the host is banned.
Parameters:
Name | Type | Description |
---|---|---|
host |
String |
- Source:
Returns:
- Type
- Boolean
isFull() → {Boolean}
Test whether the host list is full.
- Source:
Returns:
- Type
- Boolean
isStale(entry) → {Boolean}
Test whether a host is evictable.
Parameters:
Name | Type | Description |
---|---|---|
entry |
HostEntry |
- Source:
Returns:
- Type
- Boolean
(async) loadFile() → {Promise}
Read and initialize from hosts file.
- Source:
Returns:
- Type
- Promise
markAck(hostname, services)
Mark host as successfully ack'd.
Parameters:
Name | Type | Description |
---|---|---|
hostname |
String | |
services |
Number |
- Source:
markAttempt(hostname)
Mark host as failed.
Parameters:
Name | Type | Description |
---|---|---|
hostname |
String |
- Source:
markLocal(addr) → {Boolean}
Mark local address as seen during a handshake.
Parameters:
Name | Type | Description |
---|---|---|
addr |
NetAddress |
- Source:
Returns:
- Type
- Boolean
markSuccess(hostname)
Mark host as successfully connected.
Parameters:
Name | Type | Description |
---|---|---|
hostname |
String |
- Source:
(async) open() → {Promise}
Open hostlist and read hosts file.
- Source:
Returns:
- Type
- Promise
(async) populate(target) → {Promise}
Lookup hosts from dns host.
Parameters:
Name | Type | Description |
---|---|---|
target |
Object |
- Source:
Returns:
- Type
- Promise
(async) populateNode(addr) → {Promise}
Lookup node's domain.
Parameters:
Name | Type | Description |
---|---|---|
addr |
Object |
- Source:
Returns:
- Type
- Promise
(async) populateSeed(seed) → {Promise}
Populate from seed.
Parameters:
Name | Type | Description |
---|---|---|
seed |
Object |
- Source:
Returns:
- Type
- Promise
pushLocal(addr, score) → {Boolean}
Add a local address.
Parameters:
Name | Type | Description |
---|---|---|
addr |
NetAddress | |
score |
Number |
- Source:
Returns:
- Type
- Boolean
remove(hostname) → {NetAddress}
Remove host from host list.
Parameters:
Name | Type | Description |
---|---|---|
hostname |
String |
- Source:
Returns:
- Type
- NetAddress
removeNode(host) → {Boolean}
Remove a priority node.
Parameters:
Name | Type | Description |
---|---|---|
host |
String |
- Source:
Returns:
- Type
- Boolean
reset()
Reset host list.
- Source:
setNodes(nodes)
Set priority nodes.
Parameters:
Name | Type | Description |
---|---|---|
nodes |
Array.<String> |
- Source:
setSeeds(seeds)
Set initial seeds.
Parameters:
Name | Type | Description |
---|---|---|
seeds |
Array.<String> |
- Source:
size() → {Number}
Get list size.
- Source:
Returns:
- Type
- Number
start()
Start flush interval.
- Source:
stop()
Stop flush interval.
- Source:
toArray() → {Array.<NetAddress>}
Convert address list to array.
- Source:
Returns:
- Type
- Array.<NetAddress>
toJSON() → {Object}
Convert host list to json-friendly object.
- Source:
Returns:
- Type
- Object
unban(host)
Unban host.
Parameters:
Name | Type | Description |
---|---|---|
host |
String |
- Source:
(private) usedBucket(entry) → {List}
Get used bucket for host.
Parameters:
Name | Type | Description |
---|---|---|
entry |
HostEntry |
- Source:
Returns:
- Type
- List