Class: Plug::Peer

Inherits:
Object show all
Defined in:
lib/rbkb/plug/peer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr, owner) ⇒ Peer

Returns a new instance of Peer.



12
13
14
15
16
17
18
19
# File 'lib/rbkb/plug/peer.rb', line 12

def initialize(addr, owner)
  @addr = addr
  @owner = owner
  @transport = @owner.transport

  @port, @host = Socket.unpack_sockaddr_in(@addr)
  @name = "PEER-#{@host}:#{@port}(#{@transport})"
end

Instance Attribute Details

#addr ⇒ Object (readonly)

Returns the value of attribute addr.



9
10
11
# File 'lib/rbkb/plug/peer.rb', line 9

def addr
  @addr
end

#host ⇒ Object (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/rbkb/plug/peer.rb', line 9

def host
  @host
end

#mute ⇒ Object

Returns the value of attribute mute.



10
11
12
# File 'lib/rbkb/plug/peer.rb', line 10

def mute
  @mute
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/rbkb/plug/peer.rb', line 9

def name
  @name
end

#owner ⇒ Object (readonly)

Returns the value of attribute owner.



9
10
11
# File 'lib/rbkb/plug/peer.rb', line 9

def owner
  @owner
end

#port ⇒ Object (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/rbkb/plug/peer.rb', line 9

def port
  @port
end

#transport ⇒ Object (readonly)

Returns the value of attribute transport.



9
10
11
# File 'lib/rbkb/plug/peer.rb', line 9

def transport
  @transport
end

Instance Method Details

#close ⇒ Object



36
37
38
# File 'lib/rbkb/plug/peer.rb', line 36

def close
  @owner.unbind unless @transport == :UDP
end

#say(dat, sender) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/rbkb/plug/peer.rb', line 21

def say(dat, sender)
  UI.dump(sender.name, name, dat)

  if @transport == :UDP
    @owner.send_datagram(dat, @host, @port)
  else
    @owner.send_data(dat)
  end
end

#start_tls(sender) ⇒ Object



31
32
33
34
# File 'lib/rbkb/plug/peer.rb', line 31

def start_tls(sender)
  UI.logmsg(name, "#{sender.name} initiated TLS")
  @owner.start_tls
end