Class: I2P::Destination

Inherits:
Structure show all
Defined in:
lib/i2p/data/destination.rb,
lib/i2p/sdk.rb

Overview

I2P destination data structure.

Defines an endpoint in the I2P network. The destination may move around in the network, but messages sent to the destination will reach it.

Constant Summary collapse

BYTESIZE =

minimum

Since:

  • 0.1.3

387

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Structure

#==, #eql?, parse, #to_base64

Constructor Details

#initialize(public_key, signing_key, certificate = Certificate.new) ⇒ Destination

Initializes a new destination instance.

Parameters:

Since:

  • 0.1.3



28
29
30
31
32
# File 'lib/i2p/data/destination.rb', line 28

def initialize(public_key, signing_key, certificate = Certificate.new)
  @public_key  = public_key
  @signing_key = signing_key
  @certificate = certificate
end

Instance Attribute Details

#certificateCertificate

Returns:

Since:

  • 0.1.3



44
45
46
# File 'lib/i2p/data/destination.rb', line 44

def certificate
  @certificate
end

#public_keyPublicKey

Returns:

Since:

  • 0.1.3



36
37
38
# File 'lib/i2p/data/destination.rb', line 36

def public_key
  @public_key
end

#signing_keySigningPublicKey

Returns:

Since:

  • 0.1.3



40
41
42
# File 'lib/i2p/data/destination.rb', line 40

def signing_key
  @signing_key
end

Class Method Details

.read(input) ⇒ Destination

Reads a destination from the given input stream.

Parameters:

  • input (IO, StringIO)

Returns:

Since:

  • 0.1.3



18
19
20
# File 'lib/i2p/data/destination.rb', line 18

def self.read(input)
  self.new(PublicKey.read(input), SigningPublicKey.read(input), Certificate.read(input))
end

Instance Method Details

#sizeInteger Also known as: bytesize

Returns the byte size of this data structure.

Returns:

  • (Integer)

Since:

  • 0.1.3



50
51
52
# File 'lib/i2p/data/destination.rb', line 50

def size
  public_key.size + signing_key.size + certificate.size
end

#to_javaObject

Returns an instance of the Java class net.i2p.data.Destination.

This method only works with JRuby, not with MRI or YARV.



95
96
97
# File 'lib/i2p/sdk.rb', line 95

def to_java
  I2P::SDK::Destination.new(to_base64)
end

#to_sString

Returns the binary string representation of this destination.

Returns:

  • (String)

Since:

  • 0.1.3



59
60
61
62
63
64
65
66
# File 'lib/i2p/data/destination.rb', line 59

def to_s
  StringIO.open do |buffer|
    buffer.write(public_key.to_s)
    buffer.write(signing_key.to_s)
    buffer.write(certificate.to_s)
    buffer.string
  end
end