Class: TincScanner::TincMetaconnection
- Inherits:
-
Object
- Object
- TincScanner::TincMetaconnection
- Defined in:
- lib/tinc_scanner/tinc_metaconnection.rb
Overview
Represents a Tinc Metaconnection that has been set up with the Legacy Authentication Protocol
Instance Method Summary collapse
-
#initialize(host, port = 123) ⇒ TincMetaconnection
constructor
Initializes a Tinc metaconnection.
- #receive_id ⇒ Hash
- #send_id(nodename, protocol_version = '17') ⇒ Object
Constructor Details
#initialize(host, port = 123) ⇒ TincMetaconnection
Initializes a Tinc metaconnection
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tinc_scanner/tinc_metaconnection.rb', line 17 def initialize(host, port = 123) raise ArgumentError, 'Host must be a string' unless host.is_a? String raise ArgumentError, 'Port must be an integer' unless port.is_a? Integer begin @socket = TCPSocket.new(host, port) rescue SocketError, EncodingError, EOFError, IO::TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNRESET => e raise TincConnectionError, "Failed to connect to Tinc: #{e.}" end end |
Instance Method Details
#receive_id ⇒ Hash
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tinc_scanner/tinc_metaconnection.rb', line 35 def receive_id answer = @socket.gets answer.chomp! request_code, *request = answer.split raise InvalidTincMessageError, "Request code is not 0: #{request_code}" unless request_code == '0' nodename, protocol_version = request result = { nodename:, protocol_version: } return result end |
#send_id(nodename, protocol_version = '17') ⇒ Object
30 31 32 |
# File 'lib/tinc_scanner/tinc_metaconnection.rb', line 30 def send_id(nodename, protocol_version = '17') @socket.puts "0 #{nodename} #{protocol_version}" end |