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) fromJSON(json) → {NetAddress}

Instantiate net address from json object.

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

(static) fromOptions(options) → {NetAddress}

Instantiate network address from options.

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

(static) fromRaw(data, fullnullable) → {NetAddress}

Insantiate a network address from serialized data.

Parameters:
Name Type Attributes Description
data Buffer
full Boolean <nullable>

Include timestamp.

Source:
Returns:
Type
NetAddress

(static) fromReader(br, fullnullable) → {NetAddress}

Insantiate a network address from buffer reader.

Parameters:
Name Type Attributes Description
br BufferReader
full Boolean <nullable>

Include timestamp.

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

(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) fromRaw(data, fullnullable)

Inject properties from serialized data.

Parameters:
Name Type Attributes Description
data Buffer
full Boolean <nullable>

Include timestamp.

Source:

(private) fromReader(br, fullnullable)

Inject properties from buffer reader.

Parameters:
Name Type Attributes Description
br BufferReader
full Boolean <nullable>

Include timestamp.

Source:

(private) fromSocket(socket)

Inject properties from socket.

Parameters:
Name Type Description
socket net.Socket
Source:

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

hasServices(services) → {Boolean}

Test whether required services are available.

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

inspectSymbol() → {Object}

Inspect the network address.

Source:
Returns:
Type
Object

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

setHost(host)

Set host.

Parameters:
Name Type Description
host String
Source:

setNull()

Set null host.

Source:

setPort(port)

Set port.

Parameters:
Name Type Description
port Number
Source:

toJSON() → {Object}

Convert net address to json-friendly object.

Source:
Returns:
Type
Object

toRaw(fullnullable) → {Buffer}

Serialize network address.

Parameters:
Name Type Attributes Description
full Boolean <nullable>

Include timestamp.

Source:
Returns:
Type
Buffer

toWriter(bw, fullnullable) → {Buffer}

Write network address to a buffer writer.

Parameters:
Name Type Attributes Description
bw BufferWriter
full Boolean <nullable>

Include timestamp.

Source:
Returns:
Type
Buffer