Class: Wampproto::Acceptor
- Inherits:
-
Object
- Object
- Wampproto::Acceptor
- 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
-
#authenticator ⇒ Object
readonly
Returns the value of attribute authenticator.
-
#authmethod ⇒ Object
readonly
Returns the value of attribute authmethod.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
-
#session_details ⇒ Object
Returns the value of attribute session_details.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #accepted? ⇒ Boolean
-
#initialize(serializer = Serializer::JSON, authenticator = Acceptor::Authenticator) ⇒ Acceptor
constructor
A new instance of Acceptor.
- #receive(data) ⇒ Object
- #receive_message(msg) ⇒ Object
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
#authenticator ⇒ Object (readonly)
Returns the value of attribute authenticator.
18 19 20 |
# File 'lib/wampproto/acceptor.rb', line 18 def authenticator @authenticator end |
#authmethod ⇒ Object (readonly)
Returns the value of attribute authmethod.
18 19 20 |
# File 'lib/wampproto/acceptor.rb', line 18 def authmethod @authmethod end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
18 19 20 |
# File 'lib/wampproto/acceptor.rb', line 18 def serializer @serializer end |
#session_details ⇒ Object
Returns the value of attribute session_details.
19 20 21 |
# File 'lib/wampproto/acceptor.rb', line 19 def session_details @session_details end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
18 19 20 |
# File 'lib/wampproto/acceptor.rb', line 18 def session_id @session_id end |
#state ⇒ Object
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
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 = (msg) [serializer.serialize(to_send), to_send.instance_of?(Message::Welcome)] end |
#receive_message(msg) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/wampproto/acceptor.rb', line 41 def (msg) raise ProtocolViolation, "session was established, not expecting any new messages" if state == STATE_WELCOME_SENT case msg when Message::Hello (msg) when Message::Authenticate (msg) else self.state = STATE_ERROR Message::Abort.new({ message: "Received Abort" }, "wamp.error.received_abort") end end |