summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2014-01-01 19:36:35 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2014-01-01 19:36:35 +0000
commit9a22fae75fa21d7424ba7c346bf7b0740a0ce213 (patch)
tree4b424ebf8d71dc267508e8645ba0013214a76602
parent2e6a4b40e769cf6d73aae81dc975d480af585262 (diff)
downloadrabbitmq-server-9a22fae75fa21d7424ba7c346bf7b0740a0ce213.tar.gz
small refactor: simplify AMQP version negotiation a little bit
-rw-r--r--src/rabbit_reader.erl28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index 12bfa37f..eacc82c2 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -724,6 +724,14 @@ handle_input({frame_payload, Type, Channel, PayloadSize}, Data, State) ->
Type, Channel, Payload, State)
end;
+handle_input(handshake, <<"AMQP", A, B, C, D>>, State) ->
+ handshake({A, B, C, D}, State);
+handle_input(handshake, Other, #v1{sock = Sock}) ->
+ refuse_connection(Sock, {bad_header, Other});
+
+handle_input(Callback, Data, _State) ->
+ throw({bad_input, Callback, Data}).
+
%% The two rules pertaining to version negotiation:
%%
%% * If the server cannot support the protocol specified in the
@@ -732,37 +740,31 @@ handle_input({frame_payload, Type, Channel, PayloadSize}, Data, State) ->
%%
%% * The server MUST provide a protocol version that is lower than or
%% equal to that requested by the client in the protocol header.
-handle_input(handshake, <<"AMQP", 0, 0, 9, 1>>, State) ->
+handshake({0, 0, 9, 1}, State) ->
start_connection({0, 9, 1}, rabbit_framing_amqp_0_9_1, State);
%% This is the protocol header for 0-9, which we can safely treat as
%% though it were 0-9-1.
-handle_input(handshake, <<"AMQP", 1, 1, 0, 9>>, State) ->
+handshake({1, 1, 0, 9}, State) ->
start_connection({0, 9, 0}, rabbit_framing_amqp_0_9_1, State);
%% This is what most clients send for 0-8. The 0-8 spec, confusingly,
%% defines the version as 8-0.
-handle_input(handshake, <<"AMQP", 1, 1, 8, 0>>, State) ->
+handshake({1, 1, 8, 0}, State) ->
start_connection({8, 0, 0}, rabbit_framing_amqp_0_8, State);
%% The 0-8 spec as on the AMQP web site actually has this as the
%% protocol header; some libraries e.g., py-amqplib, send it when they
%% want 0-8.
-handle_input(handshake, <<"AMQP", 1, 1, 9, 1>>, State) ->
+handshake({1, 1, 9, 1}, State) ->
start_connection({8, 0, 0}, rabbit_framing_amqp_0_8, State);
%% ... and finally, the 1.0 spec is crystal clear!
-handle_input(handshake, <<"AMQP", Id, 1, 0, 0>>, State) ->
+handshake({Id, 1, 0, 0}, State) ->
become_1_0(Id, State);
-handle_input(handshake, <<"AMQP", A, B, C, D>>, #v1{sock = Sock}) ->
- refuse_connection(Sock, {bad_version, {A, B, C, D}});
-
-handle_input(handshake, Other, #v1{sock = Sock}) ->
- refuse_connection(Sock, {bad_header, Other});
-
-handle_input(Callback, Data, _State) ->
- throw({bad_input, Callback, Data}).
+handshake({A, B, C, D}, #v1{sock = Sock}) ->
+ refuse_connection(Sock, {bad_version, {A, B, C, D}}).
%% Offer a protocol version to the client. Connection.start only
%% includes a major and minor version number, Luckily 0-9 and 0-9-1