Class: WireGuard::Admin::Server

Inherits:
Client
  • Object
show all
Defined in:
lib/wire_guard/admin/server.rb

Overview

A publicly reachable peer/node that serves as a fallback to relay traffic for other VPN peers behind NATs.

@see https://github.com/pirate/wireguard-docs#bounce-server]

Instance Attribute Summary collapse

Attributes inherited from Client

#ip, #name, #private_key, #public_key

Instance Method Summary collapse

Methods inherited from Client

#==, #eql?, #hash

Constructor Details

#initialize(name:, ip:, allowed_ips:, private_key: nil, port: 51_820, device: 'eth0') ⇒ Server

rubocop:disable Metrics/ParameterLists

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wire_guard/admin/server.rb', line 18

def initialize(
  name:,
  ip:,
  allowed_ips:,
  private_key: nil,
  port: 51_820,
  device: 'eth0'
)
  super(name: name, ip: ip, private_key: private_key)

  raise ArgumentError, 'port must be present' if port.nil?
  raise ArgumentError, 'port number is invalid' unless (1..65_535).cover?(port.to_i)

  @port = port.to_i

  raise ArgumentError, 'allowed_ips must be present' if allowed_ips.nil?

  self.allowed_ips = allowed_ips

  raise ArgumentError, 'device must be present' if device.nil?
  raise ArgumentError, 'device must not be empty' if device.empty?

  @device = device
end

Instance Attribute Details

#allowed_ipsObject

Returns the value of attribute allowed_ips.



14
15
16
# File 'lib/wire_guard/admin/server.rb', line 14

def allowed_ips
  @allowed_ips
end

#deviceObject

Returns the value of attribute device.



15
16
17
# File 'lib/wire_guard/admin/server.rb', line 15

def device
  @device
end

#portObject

Returns the value of attribute port.



15
16
17
# File 'lib/wire_guard/admin/server.rb', line 15

def port
  @port
end

Instance Method Details

#to_sObject



50
51
52
# File 'lib/wire_guard/admin/server.rb', line 50

def to_s
  "#{self.class.name.split('::').last} #{name}: #{ip}:#{port} [Allowed IPs: #{allowed_ips}/#{allowed_ips.prefix} via #{device}]"
end