Class: DEVp2p::MultiplexedSession
Instance Attribute Summary
Attributes inherited from Multiplexer
#decode_buffer
Instance Method Summary
collapse
Methods inherited from Multiplexer
#active_protocol?, #add_protocol, #decode, #decode_body, #decode_header, #next_protocol, #num_active_protocols, #pop_all_frames, #pop_all_frames_as_bytes, #pop_frames, #pop_frames_for_protocol, #protocol_window_size
#add_config
Constructor Details
#initialize(privkey, hello_packet, remote_pubkey = nil) ⇒ MultiplexedSession
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/devp2p/multiplexed_session.rb', line 7
def initialize(privkey, hello_packet, remote_pubkey=nil)
@hello_packet = hello_packet
@remote_pubkey = remote_pubkey
@message_queue = SyncQueue.new @packet_queue = SyncQueue.new
@is_initiator = !!remote_pubkey
@handshake_finished = false
ecc = Crypto::ECCx.new privkey
@rlpx_session = RLPxSession.new ecc, @is_initiator
super(@rlpx_session)
send_init_msg if @is_initiator
end
|
Instance Method Details
#add_message(msg) ⇒ Object
49
50
51
|
# File 'lib/devp2p/multiplexed_session.rb', line 49
def add_message(msg)
@handshake_finished ? add_message_post_handshake(msg) : add_message_during_handshake(msg)
end
|
#add_packet(packet) ⇒ Object
encodes a packet and adds the message(s) to the message queue.
56
57
58
59
60
61
62
63
|
# File 'lib/devp2p/multiplexed_session.rb', line 56
def add_packet(packet)
raise MultiplexedSessionError, 'session is not ready' unless ready?
raise ArgumentError, 'packet must be instance of Packet' unless packet.is_a?(Packet)
super(packet)
pop_all_frames.each {|f| @message_queue.enq f.as_bytes }
end
|
#get_message ⇒ Object
25
26
27
|
# File 'lib/devp2p/multiplexed_session.rb', line 25
def get_message
@message_queue.deq
end
|
#get_packet ⇒ Object
29
30
31
|
# File 'lib/devp2p/multiplexed_session.rb', line 29
def get_packet
@packet_queue.deq
end
|
#initiator? ⇒ Boolean
37
38
39
|
# File 'lib/devp2p/multiplexed_session.rb', line 37
def initiator?
@is_initiator
end
|
#ready? ⇒ Boolean
33
34
35
|
# File 'lib/devp2p/multiplexed_session.rb', line 33
def ready?
@rlpx_session.ready?
end
|
#remote_pubkey ⇒ Object
41
42
43
|
# File 'lib/devp2p/multiplexed_session.rb', line 41
def remote_pubkey
@remote_pubkey || @rlpx_session.remote_pubkey
end
|
#remote_pubkey=(key) ⇒ Object
45
46
47
|
# File 'lib/devp2p/multiplexed_session.rb', line 45
def remote_pubkey=(key)
@remote_pubkey = key
end
|