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.
-
#hops_data ⇒ Object
Returns the value of attribute hops_data.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(version, public_key, hops_data, hmac) ⇒ Packet
constructor
A new instance of Packet.
- #to_payload ⇒ Object
Constructor Details
#initialize(version, public_key, hops_data, hmac) ⇒ Packet
Returns a new instance of Packet.
7 8 9 10 11 12 |
# File 'lib/lightning/onion/packet.rb', line 7 def initialize(version, public_key, hops_data, hmac) @version = version @public_key = public_key @hops_data = hops_data @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 |
#hops_data ⇒ Object
Returns the value of attribute hops_data.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def hops_data @hops_data 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 |
#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
14 15 16 17 18 19 20 21 22 |
# File 'lib/lightning/onion/packet.rb', line 14 def self.parse(payload) version, public_key, rest = payload.unpack('H2H66a*') hops_data = [] 20.times do |i| hops_data << Lightning::Onion::HopData.parse(rest[i * 65...i * 65 + 65]) end hmac = rest[21 * 65..-1] new(version, public_key, hops_data, hmac) end |
Instance Method Details
#to_payload ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/lightning/onion/packet.rb', line 24 def to_payload payload = +'' payload << [version.bth, public_key].pack('H2H66') payload << [hops_data.map(&:to_payload).join].pack('a1300') payload << hmac payload end |