Class: NetAddress

net~NetAddress(options)

Net Address Represents a network address.

Constructor

new NetAddress(options)

Create a network address.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Description
time Number <nullable>

Timestamp.

services Number <nullable>

Service bits.

host String <nullable>

IP address (IPv6 or IPv4).

port Number <nullable>

Port.

Properties:
Name Type Description
host Host
port Number
services Number
time Number
Source:

Members

(static, constant) DEFAULT_SERVICES :Number

Default services for unknown outbound peers.

Type:
  • Number
Source:

Methods

(static) fromHost(host, port, networknullable) → {NetAddress}

Instantiate a network address from a host and port.

Parameters:
Name Type Attributes Description
host String
port Number
network Network | NetworkType <nullable>
Source:
Returns:
Type
NetAddress

(static) fromHostname(hostname, networknullable) → {NetAddress}

Instantiate a network address from a hostname (i.e. 127.0.0.1:8333).

Parameters:
Name Type Attributes Description
hostname String
network Network | NetworkType <nullable>
Source:
Returns:
Type
NetAddress

(static) fromSocket(socket) → {NetAddress}

Instantiate a network address from a socket.

Parameters:
Name Type Description
socket net.Socket
Source:
Returns:
Type
NetAddress

compare() → {Number}

Compare against another network address.

Source:
Returns:
Type
Number

equal() → {Boolean}

Compare against another network address.

Source:
Returns:
Type
Boolean

format() → {Object}

Inspect the network address.

Source:
Returns:
Type
Object

(private) fromHost(host, port, networknullable)

Inject properties from host, port, and network.

Parameters:
Name Type Attributes Description
host String
port Number
network Network | NetworkType <nullable>
Source:

(private) fromHostname(hostname, networknullable)

Inject properties from hostname and network.

Parameters:
Name Type Attributes Description
hostname String
network Network | NetworkType <nullable>
Source:

(private) fromJSON(json) → {NetAddress}

Inject properties from json object.

Parameters:
Name Type Description
json Object
Source:
Returns:
Type
NetAddress

(private) fromOptions(options)

Inject properties from options object.

Parameters:
Name Type Description
options Object
Source:

(private) fromSocket(socket)

Inject properties from socket.

Parameters:
Name Type Description
socket net.Socket
Source:

getJSON() → {Object}

Convert net address to json-friendly object.

Source:
Returns:
Type
Object

getKey(enc) → {String|Buffer}

Get key.

Parameters:
Name Type Description
enc String
Source:
Returns:
Type
String | Buffer

getReachability(dest) → {Number}

Get reachable score to destination.

Parameters:
Name Type Description
dest NetAddress
Source:
Returns:
Type
Number

getSize() → {Number}

Calculate serialization size of address.

Source:
Returns:
Type
Number

hasKey() → {Boolean}

Test whether the peer has a key.

Source:
Returns:
Type
Boolean

hasServices(services) → {Boolean}

Test whether required services are available.

Parameters:
Name Type Description
services Number
Source:
Returns:
Type
Boolean

isIPv4() → {Boolean}

Test whether the address is IPv4.

Source:
Returns:
Type
Boolean

isIPv6() → {Boolean}

Test whether the address is IPv6.

Source:
Returns:
Type
Boolean

isLocal() → {Boolean}

Test whether the host is a local address.

Source:
Returns:
Type
Boolean

isNull() → {Boolean}

Test whether the host is null.

Source:
Returns:
Type
Boolean

isOnion() → {Boolean}

Test whether the host is an onion address.

Source:
Returns:
Type
Boolean

isRoutable() → {Boolean}

Test whether the host is routable.

Source:
Returns:
Type
Boolean

isValid() → {Boolean}

Test whether the host is valid.

Source:
Returns:
Type
Boolean

(private) read(br)

Inject properties from buffer reader.

Parameters:
Name Type Description
br BufferReader
Source:

setHost(host)

Set host.

Parameters:
Name Type Description
host String
Source:

setKey(key)

Set key.

Parameters:
Name Type Description
key Buffer
Source:

setNull()

Set null host.

Source:

setPort(port)

Set port.

Parameters:
Name Type Description
port Number
Source:

write(bw) → {Buffer}

Write network address to a buffer writer.

Parameters:
Name Type Description
bw BufferWriter
Source:
Returns:
Type
Buffer