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
]

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



93
94
95
96
97
98
99
100
# File 'lib/cztop/proxy.rb', line 93

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:



103
104
105
# File 'lib/cztop/proxy.rb', line 103

def proxy
  @proxy
end

#sideString (readonly)

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

Returns:

  • (String)

    the side, either “FRONTEND” or “BACKEND”



106
107
108
# File 'lib/cztop/proxy.rb', line 106

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



113
114
115
116
117
118
119
# File 'lib/cztop/proxy.rb', line 113

def bind(socket_type, endpoint)
  unless SOCKET_TYPES.include?(socket_type)
    raise ArgumentError, "invalid socket type: #{socket_type}"
  end
  @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



139
140
141
142
143
144
145
146
# File 'lib/cztop/proxy.rb', line 139

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



123
124
125
126
# File 'lib/cztop/proxy.rb', line 123

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.



130
131
132
133
# File 'lib/cztop/proxy.rb', line 130

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