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.



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

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

#addrObject (readonly)

Returns the value of attribute addr.



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

def addr
  @addr
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#muteObject

Returns the value of attribute mute.



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

def mute
  @mute
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



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

def owner
  @owner
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#transportObject (readonly)

Returns the value of attribute transport.



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

def transport
  @transport
end

Instance Method Details

#closeObject



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

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

#say(dat, sender) ⇒ Object



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

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

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