Class: Lightning::Onion::Packet
- Inherits:
-
Object
- Object
- Lightning::Onion::Packet
- Defined in:
- lib/lightning/onion/packet.rb
Instance Attribute Summary collapse
-
#hmac ⇒ Object
Returns the value of attribute hmac.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#routing_info ⇒ Object
Returns the value of attribute routing_info.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(version, public_key, routing_info, hmac) ⇒ Packet
constructor
A new instance of Packet.
- #last? ⇒ Boolean
- #to_payload ⇒ Object
Constructor Details
#initialize(version, public_key, routing_info, hmac) ⇒ Packet
Returns a new instance of Packet.
8 9 10 11 12 13 14 |
# File 'lib/lightning/onion/packet.rb', line 8 def initialize(version, public_key, routing_info, hmac) @version = version @public_key = public_key @routing_info = routing_info raise "invalid size #{routing_info.size}" unless routing_info.size == Packet.routing_bytesize * 2 @hmac = hmac end |
Instance Attribute Details
#hmac ⇒ Object
Returns the value of attribute hmac.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def hmac @hmac end |
#public_key ⇒ Object
Returns the value of attribute public_key.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def public_key @public_key end |
#routing_info ⇒ Object
Returns the value of attribute routing_info.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def routing_info @routing_info end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def version @version end |
Class Method Details
.parse(payload) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/lightning/onion/packet.rb', line 20 def self.parse(payload) version, public_key, rest = payload.unpack('aH66a*') routing_info = rest[0...routing_bytesize].bth hmac = rest[routing_bytesize..-1].bth new(version, public_key, routing_info, hmac) end |
Instance Method Details
#last? ⇒ Boolean
35 36 37 |
# File 'lib/lightning/onion/packet.rb', line 35 def last? hmac == '00' * 32 end |
#to_payload ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/lightning/onion/packet.rb', line 27 def to_payload payload = +'' payload << [version, public_key].pack('aH66') payload << routing_info.htb payload << hmac.htb payload end |