Class: CZTop::Proxy::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/cztop/proxy.rb

Overview

Used to configure the socket on one side of a CZTop::Proxy.

Constant Summary collapse

SOCKET_TYPES =

Returns supported socket types.

Returns:

  • (Array<Symbol>)

    supported socket types

%i[
  PAIR PUB SUB REQ REP
  DEALER ROUTER PULL PUSH
  XPUB XSUB
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy, side) ⇒ Configurator

Returns a new instance of Configurator.

Parameters:

  • proxy (Proxy)

    the proxy instance

  • side (Symbol)

    :frontend or :backend



104
105
106
107
108
109
110
111
# File 'lib/cztop/proxy.rb', line 104

def initialize(proxy, side)
  @proxy = proxy
  @side  = case side
           when :frontend then 'FRONTEND'
           when :backend then 'BACKEND'
           else raise ArgumentError, "invalid side: #{side.inspect}"
           end
end

Instance Attribute Details

#proxyProxy (readonly)

Returns the proxy this CZTop::Proxy::Configurator works on.

Returns:



114
115
116
# File 'lib/cztop/proxy.rb', line 114

def proxy
  @proxy
end

#sideString (readonly)

Returns the side, either “FRONTEND” or “BACKEND”.

Returns:

  • (String)

    the side, either “FRONTEND” or “BACKEND”



117
118
119
# File 'lib/cztop/proxy.rb', line 117

def side
  @side
end

Instance Method Details

#bind(socket_type, endpoint) ⇒ void

This method returns an undefined value.

Creates and binds a serverish socket.

Parameters:

  • socket_type (Symbol)

    one of SOCKET_TYPES

  • endpoint (String)

    endpoint to bind to

Raises:

  • (ArgumentError)

    if the given socket type is invalid



124
125
126
127
128
129
# File 'lib/cztop/proxy.rb', line 124

def bind(socket_type, endpoint)
  raise ArgumentError, "invalid socket type: #{socket_type}" unless SOCKET_TYPES.include?(socket_type)

  @proxy.actor << [@side, socket_type.to_s, endpoint]
  @proxy.actor.wait
end

#CURVE_server!(cert) ⇒ Object

Note:

You’ll have to use a Authenticator.

Configure CURVE authentication on this socket.

Parameters:

  • cert (Certificate)

    this server’s certificate, so remote clients are able to authenticate this server



152
153
154
155
156
157
158
159
# File 'lib/cztop/proxy.rb', line 152

def CURVE_server!(cert)
  public_key = cert.public_key
  secret_key = cert.secret_key or
    raise ArgumentError, 'no secret key in certificate'

  @proxy.actor << ['CURVE', @side, public_key, secret_key]
  @proxy.actor.wait
end

#domain=(domain) ⇒ Object

Set ZAP domain for authentication.

Parameters:

  • domain (String)

    the ZAP domain



134
135
136
137
# File 'lib/cztop/proxy.rb', line 134

def domain=(domain)
  @proxy.actor << ['DOMAIN', @side, domain]
  @proxy.actor.wait
end

#PLAIN_server!Object

Note:

You’ll have to use a Authenticator.

Configure PLAIN authentication on this socket.



142
143
144
145
# File 'lib/cztop/proxy.rb', line 142

def PLAIN_server!
  @proxy.actor << ['PLAIN', @side]
  @proxy.actor.wait
end