Class: Wampproto::Acceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/wampproto/acceptor.rb,
lib/wampproto/acceptor/request.rb,
lib/wampproto/acceptor/response.rb,
lib/wampproto/acceptor/authenticator.rb

Overview

Accepts Request

Defined Under Namespace

Classes: AuthenticateRequest, Authenticator, Request, Response

Constant Summary collapse

STATE_NONE =

rubocop:disable Metrics/ClassLength:

0
STATE_HELLO_RECEIVED =
1
STATE_CHALLENGE_SENT =
2
STATE_WELCOME_SENT =
3
STATE_ERROR =
4
ROUTER_ROLES =
{ dealer: {}, broker: {} }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serializer = Serializer::JSON, authenticator = Acceptor::Authenticator) ⇒ Acceptor

Returns a new instance of Acceptor.



21
22
23
24
25
26
27
28
# File 'lib/wampproto/acceptor.rb', line 21

def initialize(serializer = Serializer::JSON, authenticator = Acceptor::Authenticator)
  @serializer = serializer
  @authenticator = authenticator
  @state = STATE_NONE
  @session_id = create_session_id
  # @authmethod = authenticator.authmethod
  # @session_details = SessionDetails
end

Instance Attribute Details

#authenticatorObject (readonly)

Returns the value of attribute authenticator.



18
19
20
# File 'lib/wampproto/acceptor.rb', line 18

def authenticator
  @authenticator
end

#authmethodObject (readonly)

Returns the value of attribute authmethod.



18
19
20
# File 'lib/wampproto/acceptor.rb', line 18

def authmethod
  @authmethod
end

#serializerObject (readonly)

Returns the value of attribute serializer.



18
19
20
# File 'lib/wampproto/acceptor.rb', line 18

def serializer
  @serializer
end

#session_detailsObject

Returns the value of attribute session_details.



19
20
21
# File 'lib/wampproto/acceptor.rb', line 19

def session_details
  @session_details
end

#session_idObject (readonly)

Returns the value of attribute session_id.



18
19
20
# File 'lib/wampproto/acceptor.rb', line 18

def session_id
  @session_id
end

#stateObject

Returns the value of attribute state.



19
20
21
# File 'lib/wampproto/acceptor.rb', line 19

def state
  @state
end

Instance Method Details

#accepted?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/wampproto/acceptor.rb', line 30

def accepted?
  @state == STATE_WELCOME_SENT
end

#receive(data) ⇒ Object



34
35
36
37
38
39
# File 'lib/wampproto/acceptor.rb', line 34

def receive(data)
  msg = serializer.deserialize(data)
  to_send = receive_message(msg)

  [serializer.serialize(to_send), to_send.instance_of?(Message::Welcome)]
end

#receive_message(msg) ⇒ Object

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wampproto/acceptor.rb', line 41

def receive_message(msg)
  raise ProtocolViolation, "session was established, not expecting any new messages" if state == STATE_WELCOME_SENT

  case msg
  when Message::Hello
    handle_hello_message(msg)
  when Message::Authenticate
    handle_authenticate_message(msg)
  else
    self.state = STATE_ERROR
    Message::Abort.new({ message: "Received Abort" }, "wamp.error.received_abort")
  end
end