Class: Ciri::P2P::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/ciri/p2p/address.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip:, udp_port:, tcp_port: udp_port) ⇒ Address

Returns a new instance of Address.



30
31
32
33
34
# File 'lib/ciri/p2p/address.rb', line 30

def initialize(ip:, udp_port:, tcp_port: udp_port)
  @ip = ip.is_a?(IPAddr) ? ip : IPAddr.new(ip)
  @udp_port = udp_port
  @tcp_port = tcp_port
end

Instance Attribute Details

#ipObject (readonly)

Returns the value of attribute ip.



28
29
30
# File 'lib/ciri/p2p/address.rb', line 28

def ip
  @ip
end

#tcp_portObject (readonly)

Returns the value of attribute tcp_port.



28
29
30
# File 'lib/ciri/p2p/address.rb', line 28

def tcp_port
  @tcp_port
end

#udp_portObject (readonly)

Returns the value of attribute udp_port.



28
29
30
# File 'lib/ciri/p2p/address.rb', line 28

def udp_port
  @udp_port
end

Instance Method Details

#<=>(other) ⇒ Object



40
41
42
# File 'lib/ciri/p2p/address.rb', line 40

def <=>(other)
  ip <=> other.ip
end

#==(other) ⇒ Object



36
37
38
# File 'lib/ciri/p2p/address.rb', line 36

def ==(other)
  self.class == other.class && ip == other.ip && udp_port == other.udp_port
end

#inspectObject



44
45
46
# File 'lib/ciri/p2p/address.rb', line 44

def inspect
  "<PeerStore::Address #{ip.inspect} udp_port: #{udp_port} tcp_port: #{tcp_port}>"
end