Class: Peer

servers/peer~ Peer

Server for communication with peers

new Peer(app, config, logger, runner, ini, crypter, connectionsList)

Create the service
Parameters:
Name Type Description
app App Application
config object Configuration
logger Logger Logger service
runner Runner Runner service
ini Ini Ini service
crypter Crypter Crypter service
connectionsList ConnectionsList Connections List service

Members


<static> provides :string

Service name is 'servers.peer'
Type:
  • string

<static> requires :Array.<string>

Dependencies as constructor arguments
Type:
  • Array.<string>

<static> addressTimeout :number

Tracker address response timeout
Type:
  • number

<static> connectTimeout :number

Connect timeout
Type:
  • number

<static> establishTimeout :number

Finish handshake timeout
Type:
  • number

<static> failureTimeout :number

Failed connect retry timeout
Type:
  • number

<static> pingTimeout :number

Will send keep alive at this interval
Type:
  • number

<static> pongTimeout :number

No data in socket timeout
Type:
  • number

<static> closeTimeout :number

Close connection timeout
Type:
  • number

<static> punchingAttempts :number

Number of punching packets
Type:
  • number

_tracker

Retrieve tracker server

_front

Retrieve front server

Methods


<async> init(name)

Initialize the server
Parameters:
Name Type Description
name string Config section name
Returns:
Type
Promise

<async> start(name)

Start the server
Parameters:
Name Type Description
name string Config section name
Returns:
Type
Promise

<async> stop(name)

Stop the server
Parameters:
Name Type Description
name string Config section name
Returns:
Type
Promise

openServer(tracker, name, options)

Open server connection
Parameters:
Name Type Description
tracker string Tracker name
name string Connection name on tracker
options object
Properties
Name Type Description
connectAddress string Connect front to
connectPort string Connect front to
encrypted string Is encryption is required
fixed string Is clients list is fixed
peers Array.<string> List of allowed peers when fixed

openClient(tracker, name, options)

Open client connection
Parameters:
Name Type Description
tracker string Tracker name
name string Connection name on tracker
options object
Properties
Name Type Description
listenAddress string Front listen on
listenPort string Front listen on
encrypted string Is encryption is required
fixed string Is clients list is fixed
peers Array.<string> List of allowed peers when fixed

close(tracker, name)

Close connection
Parameters:
Name Type Description
tracker string Tracker name
name string Connection name on tracker

connect(tracker, name, type)

Connect to server
Parameters:
Name Type Description
tracker string Tracker name
name string Connection name on tracker
type string 'internal' or 'external'

createSession(name, socket)

Create UTP session
Parameters:
Name Type Description
name string | null Connection full name
socket object Established socket
Returns:
Type
object

send(sessionId, data [, end])

Send data to peer
Parameters:
Name Type Argument Description
sessionId string Session ID
data Buffer | null Message
end boolean <optional>
End socket

sendConnectRequest(sessionId)

Send request for establishing connection
Parameters:
Name Type Description
sessionId string Session ID

sendInnerMessage(sessionId, encrypted, data)

Send inner message to a peer
Parameters:
Name Type Description
sessionId string Session ID
encrypted boolean Encrypted flag
data * Message

end(sessionId)

End session
Parameters:
Name Type Description
sessionId string Session ID

onConnection(socket)

Incoming connection handler
Parameters:
Name Type Description
socket object Client socket

onMessage(sessionId, data)

Peer message handler
Parameters:
Name Type Description
sessionId string Session ID
data Buffer Message

onError(sessionId, error)

Socket error handler
Parameters:
Name Type Description
sessionId string Session ID
error Error Error

onClose(sessionId)

Socket termination handler
Parameters:
Name Type Description
sessionId string Session ID

onTimeout(sessionId)

Socket timeout handler
Parameters:
Name Type Description
sessionId string Session ID

_checkTimeout()

Check socket timeout