ethereumjs-client › "net/peer/peer" › Peer
Network peer
memberof
module:net/peer
-
EventEmitter
↳ Peer
↳ RlpxPeer
- addListener
- bindProtocol
- emit
- eventNames
- getMaxListeners
- listenerCount
- listeners
- off
- on
- once
- prependListener
- prependOnceListener
- rawListeners
- removeAllListeners
- removeListener
- setMaxListeners
- toString
- understands
- listenerCount
+ new Peer(options
: PeerOptions): Peer
Overrides void
Defined in lib/net/peer/peer.ts:46
Create new peer
Parameters:
Name | Type |
---|---|
options |
PeerOptions |
Returns: Peer
• address: string
Defined in lib/net/peer/peer.ts:36
• bound: Map‹string, BoundProtocol›
Defined in lib/net/peer/peer.ts:39
• config: Config
Defined in lib/net/peer/peer.ts:34
• eth: BoundProtocol | undefined
Defined in lib/net/peer/peer.ts:46
• id: string
Defined in lib/net/peer/peer.ts:35
• inbound: boolean
Defined in lib/net/peer/peer.ts:37
• les: BoundProtocol | undefined
Defined in lib/net/peer/peer.ts:45
• server: Server | undefined
Defined in lib/net/peer/peer.ts:38
▪ defaultMaxListeners: number
Inherited from Sender.defaultMaxListeners
Defined in node_modules/@types/node/events.d.ts:45
▪ errorMonitor: keyof symbol
Inherited from Sender.errorMonitor
Defined in node_modules/@types/node/events.d.ts:55
This symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular
'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an
'error'
event is emitted, therefore the process will still crash if no
regular 'error'
listener is installed.
• get idle(): boolean
Defined in lib/net/peer/peer.ts:71
Get idle state of peer
type
{boolean}
Returns: boolean
• set idle(value
: boolean): void
Defined in lib/net/peer/peer.ts:79
Set idle state of peer
type
{boolean}
Parameters:
Name | Type |
---|---|
value |
boolean |
Returns: void
▸ addListener(event
: string | symbol, listener
: function): this
Inherited from Sender.addListener
Defined in node_modules/@types/node/events.d.ts:62
Parameters:
▪ event: string | symbol
▪ listener: function
▸ (...args
: any[]): void
Parameters:
Name | Type |
---|---|
...args |
any[] |
Returns: this
▸ bindProtocol(protocol
: Protocol, sender
: Sender): Promise‹void›
Defined in lib/net/peer/peer.ts:107
Adds a protocol to this peer given a sender instance. Protocol methods will be accessible via a field with the same name as protocol. New methods will be added corresponding to each message defined by the protocol, in addition to send() and request() methods that takes a message name and message arguments. send() only sends a message without waiting for a response, whereas request() also sends the message but will return a promise that resolves with the response payload.
example
await peer.bindProtocol(ethProtocol, sender)
// Example: Directly call message name as a method on the bound protocol
const headers1 = await peer.eth.getBlockHeaders(1, 100, 0, 0)
// Example: Call request() method with message name as first parameter
const headers2 = await peer.eth.request('getBlockHeaders', 1, 100, 0, 0)
// Example: Call send() method with message name as first parameter and
// wait for response message as an event
peer.eth.send('getBlockHeaders', 1, 100, 0, 0)
peer.eth.on('message', ({ data }) => console.log(Received ${data.length} headers
))
Parameters:
Name | Type | Description |
---|---|---|
protocol |
Protocol | protocol instance |
sender |
Sender | Sender instance provided by subclass |
Returns: Promise‹void›
▸ emit(event
: string | symbol, ...args
: any[]): boolean
Defined in node_modules/@types/node/events.d.ts:72
Parameters:
Name | Type |
---|---|
event |
string | symbol |
...args |
any[] |
Returns: boolean
▸ eventNames(): Array‹string | symbol›
Inherited from Sender.eventNames
Defined in node_modules/@types/node/events.d.ts:77
Returns: Array‹string | symbol›
▸ getMaxListeners(): number
Inherited from Sender.getMaxListeners
Defined in node_modules/@types/node/events.d.ts:69
Returns: number
▸ listenerCount(event
: string | symbol): number
Inherited from Sender.listenerCount
Defined in node_modules/@types/node/events.d.ts:73
Parameters:
Name | Type |
---|---|
event |
string | symbol |
Returns: number
▸ listeners(event
: string | symbol): Function[]
Inherited from Sender.listeners
Defined in node_modules/@types/node/events.d.ts:70
Parameters:
Name | Type |
---|---|
event |
string | symbol |
Returns: Function[]
▸ off(event
: string | symbol, listener
: function): this
Defined in node_modules/@types/node/events.d.ts:66
Parameters:
▪ event: string | symbol
▪ listener: function
▸ (...args
: any[]): void
Parameters:
Name | Type |
---|---|
...args |
any[] |
Returns: this
▸ on(event
: string | symbol, listener
: function): this
Defined in node_modules/@types/node/events.d.ts:63
Parameters:
▪ event: string | symbol
▪ listener: function
▸ (...args
: any[]): void
Parameters:
Name | Type |
---|---|
...args |
any[] |
Returns: this
▸ once(event
: string | symbol, listener
: function): this
Defined in node_modules/@types/node/events.d.ts:64
Parameters:
▪ event: string | symbol
▪ listener: function
▸ (...args
: any[]): void
Parameters:
Name | Type |
---|---|
...args |
any[] |
Returns: this
▸ prependListener(event
: string | symbol, listener
: function): this
Inherited from Sender.prependListener
Defined in node_modules/@types/node/events.d.ts:75
Parameters:
▪ event: string | symbol
▪ listener: function
▸ (...args
: any[]): void
Parameters:
Name | Type |
---|---|
...args |
any[] |
Returns: this
▸ prependOnceListener(event
: string | symbol, listener
: function): this
Inherited from Sender.prependOnceListener
Defined in node_modules/@types/node/events.d.ts:76
Parameters:
▪ event: string | symbol
▪ listener: function
▸ (...args
: any[]): void
Parameters:
Name | Type |
---|---|
...args |
any[] |
Returns: this
▸ rawListeners(event
: string | symbol): Function[]
Inherited from Sender.rawListeners
Defined in node_modules/@types/node/events.d.ts:71
Parameters:
Name | Type |
---|---|
event |
string | symbol |
Returns: Function[]
▸ removeAllListeners(event?
: string | symbol): this
Inherited from Sender.removeAllListeners
Defined in node_modules/@types/node/events.d.ts:67
Parameters:
Name | Type |
---|---|
event? |
string | symbol |
Returns: this
▸ removeListener(event
: string | symbol, listener
: function): this
Inherited from Sender.removeListener
Defined in node_modules/@types/node/events.d.ts:65
Parameters:
▪ event: string | symbol
▪ listener: function
▸ (...args
: any[]): void
Parameters:
Name | Type |
---|---|
...args |
any[] |
Returns: this
▸ setMaxListeners(n
: number): this
Inherited from Sender.setMaxListeners
Defined in node_modules/@types/node/events.d.ts:68
Parameters:
Name | Type |
---|---|
n |
number |
Returns: this
▸ toString(withFullId
: boolean): string
Defined in lib/net/peer/peer.ts:126
Parameters:
Name | Type | Default |
---|---|---|
withFullId |
boolean | false |
Returns: string
▸ understands(protocolName
: string): boolean
Defined in lib/net/peer/peer.ts:122
Return true if peer understand the specified protocol name
Parameters:
Name | Type | Description |
---|---|---|
protocolName |
string |
Returns: boolean
▸ listenerCount(emitter
: EventEmitter, event
: string | symbol): number
Inherited from Sender.listenerCount
Defined in node_modules/@types/node/events.d.ts:44
deprecated
since v4.0.0
Parameters:
Name | Type |
---|---|
emitter |
EventEmitter |
event |
string | symbol |
Returns: number