Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 27b2c91ea -> 979030344


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/97903034/console/stand-alone/plugin/lib/rhea-min.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/lib/rhea-min.js 
b/console/stand-alone/plugin/lib/rhea-min.js
index 42ca130..939f401 100644
--- a/console/stand-alone/plugin/lib/rhea-min.js
+++ b/console/stand-alone/plugin/lib/rhea-min.js
@@ -1,6 +1,4 @@
-require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof 
require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var 
f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var 
l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return 
s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof 
require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return 
s}({1:[function(require,module,exports){(function(process,Buffer){"use 
strict";var frames=require("./frames.js");var log=require("./log.js");var 
sasl=require("./sasl.js");var types=require("./types.js");var 
util=require("./util.js");var EndpointState=require("./endpoint.js");var 
Session=require("./session.js");var Transport=require("./transport.js");var 
net=require("net");var tls=require("tls");var 
EventEmitter=require("events").EventEmitter;var AMQP_PROTOCOL_ID=0;var 
TLS_PROTOCOL_ID=2;function ConnectionError(message,condition,connection){Error
 
.call(this);Error.captureStackTrace(this,this.constructor);this.message=message;this.condition=condition;this.description=message;this.connection=connection}require("util").inherits(ConnectionError,Error);function
 get_socket_id(socket){if(socket.get_id_string)return 
socket.get_id_string();return socket.localAddress+":"+socket.localPort+" -> 
"+socket.remoteAddress+":"+socket.remotePort}function 
session_per_connection(conn){var 
ssn=null;return{get_session:function(){if(!ssn){ssn=conn.create_session();ssn.begin()}return
 ssn}}}function restrict(count,f){if(count){var current=count;var reset;return 
function(successful_attempts){if(reset!==successful_attempts){current=count;reset=successful_attempts}if(current--)return
 f(successful_attempts);else return-1}}else{return f}}function 
backoff(initial,max){var delay=initial;var reset;return 
function(successful_attempts){if(reset!==successful_attempts){delay=initial;reset=successful_attempts}var
 current=delay;var next=delay*2;delay=max>next?next
 :max;return current}}function 
get_connect_fn(options){if(options.transport===undefined||options.transport==="tcp"){return
 net.connect}else 
if(options.transport==="tls"||options.transport==="ssl"){return 
tls.connect}else{throw Error("Unrecognised transport: 
"+options.transport)}}function connection_details(options){var 
details={};details.connect=options.connect?options.connect:get_connect_fn(options);details.host=options.host?options.host:"localhost";details.port=options.port?options.port:5672;details.options=options;return
 details}var 
aliases=["container_id","hostname","max_frame_size","channel_max","idle_time_out","outgoing_locales","incoming_locales","offered_capabilities","desired_capabilities","properties"];function
 remote_property_shortcut(name){return function(){return 
this.remote.open?this.remote.open[name]:undefined}}var conn_counter=1;var 
Connection=function(options,container){this.options={};if(options){for(var k in 
options){this.options[k]=options[k]}}this.container=conta
 
iner;if(!this.options.id){this.options.id="connection-"+conn_counter++}if(!this.options.container_id){this.options.container_id=container?container.id:util.generate_uuid()}if(!this.options.connection_details){var
 self=this;this.options.connection_details=function(){return 
connection_details(self.options)}}var 
reconnect=this.get_option("reconnect",true);if(typeof 
reconnect==="boolean"&&reconnect){var 
initial=this.get_option("initial_reconnect_delay",100);var 
max=this.get_option("max_reconnect_delay",6e4);this.options.reconnect=restrict(this.get_option("reconnect_limit"),backoff(initial,max))}else
 if(typeof reconnect==="number"){var 
fixed=this.options.reconnect;this.options.reconnect=restrict(this.get_option("reconnect_limit"),function(){return
 fixed})}this.registered=false;this.state=new 
EndpointState;this.local_channel_map={};this.remote_channel_map={};this.local={};this.remote={};this.local.open=frames.open(this.options);this.local.close=frames.close({});this.session_policy=session
 _per_connection(this);this.amqp_transport=new 
Transport(this.options.id,AMQP_PROTOCOL_ID,frames.TYPE_AMQP,this);this.sasl_transport=undefined;this.transport=this.amqp_transport;this.conn_established_counter=0;this.heartbeat_out=undefined;this.heartbeat_in=undefined;this.abort_idle=false;this.socket_ready=false;this.scheduled_reconnect=undefined;this.default_sender=undefined;for(var
 i in aliases){var 
f=aliases[i];Object.defineProperty(this,f,{get:remote_property_shortcut(f)})}Object.defineProperty(this,"error",{get:function(){return
 
this.remote.close?this.remote.close.error:undefined}})};Connection.prototype=Object.create(EventEmitter.prototype);Connection.prototype.constructor=Connection;Connection.prototype.dispatch=function(name,context){log.events("Connection
 got event: 
"+name);if(this.listeners(name).length){EventEmitter.prototype.emit.apply(this,arguments);return
 true}else if(this.container){return 
this.container.dispatch.apply(this.container,arguments)}};Connection.prototype.r
 
eset=function(){if(this.abort_idle){this.abort_idle=false;this.local.close.error=undefined;this.state=new
 EndpointState;this.state.open()}this.amqp_transport=new 
Transport(this.options.id,AMQP_PROTOCOL_ID,frames.TYPE_AMQP,this);this.sasl_transport=undefined;this.transport=this.amqp_transport;this.state.disconnected();this.remote={};this.remote_channel_map={};for(var
 k in 
this.local_channel_map){this.local_channel_map[k].reset()}this.socket_ready=false};Connection.prototype.connect=function(){this.is_server=false;this._connect(this.options.connection_details(this.conn_established_counter));this.open();return
 
this};Connection.prototype.reconnect=function(){this.scheduled_reconnect=undefined;log.reconnect("reconnecting...");this.reset();this._connect(this.options.connection_details(this.conn_established_counter));process.nextTick(this._process.bind(this));return
 
this};Connection.prototype._connect=function(details){if(details.connect){this.init(details.connect(details.port,details.host
 
,details.options,this.connected.bind(this)))}else{this.init(get_connect_fn(details)(details.port,details.host,details.options,this.connected.bind(this)))}return
 
this};Connection.prototype.accept=function(socket){this.is_server=true;log.io("["+this.id+"]
 client accepted: "+get_socket_id(socket));this.socket_ready=true;return 
this.init(socket)};Connection.prototype.init=function(socket){this.socket=socket;this.socket.on("data",this.input.bind(this));this.socket.on("error",this.on_error.bind(this));this.socket.on("end",this.eof.bind(this));if(this.is_server){var
 
mechs;if(this.container&&Object.getOwnPropertyNames(this.container.sasl_server_mechanisms).length){mechs=this.container.sasl_server_mechanisms}if(this.socket.encrypted&&this.socket.authorized&&this.get_option("enable_sasl_external",false)){mechs=sasl.server_add_external(mechs?util.clone(mechs):{})}if(mechs){this.sasl_transport=new
 sasl.Server(this,mechs)}}else{var 
mechanisms=this.get_option("sasl_mechanisms");if(!mechanisms){va
 r username=this.get_option("username");var 
password=this.get_option("password");if(username){mechanisms=sasl.client_mechanisms();if(password)mechanisms.enable_plain(username,password);else
 
mechanisms.enable_anonymous(username)}}if(this.socket.encrypted&&this.options.cert&&this.get_option("enable_sasl_external",false)){if(!mechanisms)mechanisms=sasl.client_mechanisms();mechanisms.enable_external()}if(mechanisms){this.sasl_transport=new
 
sasl.Client(this,mechanisms)}}this.transport=this.sasl_transport?this.sasl_transport:this.amqp_transport;return
 this};Connection.prototype.attach_sender=function(options){return 
this.session_policy.get_session().attach_sender(options)};Connection.prototype.open_sender=Connection.prototype.attach_sender;Connection.prototype.attach_receiver=function(options){return
 
this.session_policy.get_session().attach_receiver(options)};Connection.prototype.open_receiver=Connection.prototype.attach_receiver;Connection.prototype.get_option=function(name,default_value)
 {if(this.options[name]!==undefined)return this.options[name];else 
if(this.container)return this.container.get_option(name,default_value);else 
return 
default_value};Connection.prototype.send=function(msg){if(this.default_sender===undefined){this.default_sender=this.open_sender({target:{}})}return
 
this.default_sender.send(msg)};Connection.prototype.connected=function(){this.socket_ready=true;this.conn_established_counter++;log.io("["+this.options.id+"]
 connected 
"+get_socket_id(this.socket));this.output()};Connection.prototype.sasl_failed=function(text){this.transport_error={condition:"amqp:unauthorized-access",description:text};this._handle_error()};Connection.prototype._handle_error=function(){var
 error=this.get_error();if(error){var 
handled=this.dispatch("connection_error",this._context());handled=this.dispatch("connection_close",this._context())||handled;if(!handled){EventEmitter.prototype.emit.call(this.container,"error",new
 ConnectionError(error.description,error.condition,this)
 )}return true}else{return 
false}};Connection.prototype.get_error=function(){if(this.transport_error)return
 this.transport_error;if(this.remote.close&&this.remote.close.error)return 
this.remote.close.error;return 
undefined};Connection.prototype.output=function(){if(this.socket&&this.socket_ready){if(this.heartbeat_out)clearTimeout(this.heartbeat_out);this.transport.write(this.socket);if((this.is_closed()&&this.state.has_settled()||this.abort_idle||this.transport_error)&&!this.transport.has_writes_pending()){this.socket.end()}else
 
if(this.is_open()&&this.remote.open.idle_time_out){this.heartbeat_out=setTimeout(this._write_frame.bind(this),this.remote.open.idle_time_out/2)}}};Connection.prototype.input=function(buff){if(this.heartbeat_in)clearTimeout(this.heartbeat_in);log.io("["+this.options.id+"]
 read "+buff.length+" bytes");var 
buffer;if(this.previous_input){buffer=Buffer.concat([this.previous_input,buff],this.previous_input.length+buff.length);this.previous_input=null}else{buffer=b
 uff}var 
read=this.transport.read(buffer,this);if(read<buffer.length){this.previous_input=buffer.slice(read)}if(this.local.open.idle_time_out)this.heartbeat_in=setTimeout(this.idle.bind(this),this.local.open.idle_time_out);if(this.transport.has_writes_pending()){this.output()}else
 if(this.is_closed()&&this.state.has_settled()){this.socket.end()}else 
if(this.is_open()&&this.remote.open.idle_time_out&&!this.heartbeat_out){this.heartbeat_out=setTimeout(this._write_frame.bind(this),this.remote.open.idle_time_out/2)}};Connection.prototype.idle=function(){if(this.is_open()){this.abort_idle=true;this.local.close.error={condition:"amqp:resource-limit-exceeded",description:"max
 idle time 
exceeded"};this.close()}};Connection.prototype.on_error=function(e){console.log("["+this.options.id+"]
 error: 
"+e);this._disconnected()};Connection.prototype.eof=function(e){this._disconnected()};Connection.prototype._disconnected=function(){if(this.heartbeat_out)clearTimeout(this.heartbeat_out);if(this.heart
 
beat_in)clearTimeout(this.heartbeat_in);if(!this.is_closed()&&this.scheduled_reconnect==undefined){if(!this.dispatch("disconnected",this._context())){console.log("["+this.options.id+"]
 
disconnected")}if(!this.is_server&&!this.transport_error&&this.options.reconnect){var
 
delay=this.options.reconnect(this.conn_established_counter);if(delay>=0){log.reconnect("Scheduled
 reconnect in 
"+delay+"ms");this.scheduled_reconnect=setTimeout(this.reconnect.bind(this),delay)}}}};Connection.prototype.open=function(){if(this.state.open()){this._register()}};Connection.prototype.close=function(error){if(error)this.local.close.error=error;if(this.state.close()){this._register()}};Connection.prototype.is_open=function(){return
 this.state.is_open()};Connection.prototype.is_closed=function(){return 
this.state.is_closed()};Connection.prototype.create_session=function(){var 
i=0;while(this.local_channel_map[i])i++;var session=new 
Session(this,i);this.local_channel_map[i]=session;return session};Connection.p
 
rototype.on_open=function(frame){if(this.state.remote_opened()){this.remote.open=frame.performative;this.open();this.dispatch("connection_open",this._context())}else{throw
 Error("Open already 
received")}};Connection.prototype.on_close=function(frame){if(this.state.remote_closed()){this.remote.close=frame.performative;this.close();if(this.remote.close.error){this._handle_error()}else{this.dispatch("connection_close",this._context())}if(this.heartbeat_out)clearTimeout(this.heartbeat_out)}else{throw
 Error("Close already 
received")}};Connection.prototype._register=function(){if(!this.registered){this.registered=true;process.nextTick(this._process.bind(this))}};Connection.prototype._process=function(){this.registered=false;do{if(this.state.need_open()){this._write_open()}for(var
 k in 
this.local_channel_map){this.local_channel_map[k]._process()}if(this.state.need_close()){this._write_close()}}while(!this.state.has_settled())};Connection.prototype._write_frame=function(channel,frame,payloa
 
d){this.amqp_transport.encode(frames.amqp_frame(channel,frame,payload));this.output()};Connection.prototype._write_open=function(){this._write_frame(0,this.local.open.described())};Connection.prototype._write_close=function(){this._write_frame(0,this.local.close.described())};Connection.prototype.on_begin=function(frame){var
 
session;if(frame.performative.remote_channel===null||frame.performative.remote_channel===undefined){session=this.create_session();session.local.begin.remote_channel=frame.channel}else{session=this.local_channel_map[frame.performative.remote_channel];if(!session)throw
 Error("Invalid value for remote channel 
"+frame.performative.remote_channel)}session.on_begin(frame);this.remote_channel_map[frame.channel]=session};Connection.prototype.get_peer_certificate=function(){if(this.socket&&this.socket.getPeerCertificate){return
 this.socket.getPeerCertificate()}else{return 
undefined}};Connection.prototype.get_tls_socket=function(){if(this.socket&&(this.options.transport==
 ="tls"||this.options.transport==="ssl")){return this.socket}else{return 
undefined}};Connection.prototype._context=function(c){var 
context=c?c:{};context.connection=this;if(this.container)context.container=this.container;return
 context};function 
delegate_to_session(name){Connection.prototype["on_"+name]=function(frame){var 
session=this.remote_channel_map[frame.channel];if(!session){throw Error(name+" 
received on invalid channel 
"+frame.channel)}session["on_"+name](frame)}}delegate_to_session("end");delegate_to_session("attach");delegate_to_session("detach");delegate_to_session("transfer");delegate_to_session("disposition");delegate_to_session("flow");module.exports=Connection}).call(this,require("_process"),require("buffer").Buffer)},{"./endpoint.js":2,"./frames.js":3,"./log.js":5,"./sasl.js":8,"./session.js":9,"./transport.js":11,"./types.js":12,"./util.js":13,_process:22,buffer:16,events:20,net:15,tls:15,util:30}],2:[function(require,module,exports){"use
 strict";var EndpointState=f
 
unction(){this.init()};EndpointState.prototype.init=function(){this.local_open=false;this.remote_open=false;this.open_requests=0;this.close_requests=0;this.initialised=false};EndpointState.prototype.open=function(){this.initialised=true;if(!this.local_open){this.local_open=true;this.open_requests++;return
 true}else{return 
false}};EndpointState.prototype.close=function(){if(this.local_open){this.local_open=false;this.close_requests++;return
 true}else{return false}};EndpointState.prototype.disconnected=function(){var 
was_open=this.local_open;this.init();if(was_open){this.open()}else{this.close()}};EndpointState.prototype.remote_opened=function(frame){if(!this.remote_open){this.remote_open=true;return
 true}else{return 
false}};EndpointState.prototype.remote_closed=function(frame){if(this.remote_open){this.remote_open=false;return
 true}else{return false}};EndpointState.prototype.is_open=function(){return 
this.local_open&&this.remote_open};EndpointState.prototype.is_closed=function(){retu
 rn 
this.initialised&&!this.local_open&&!this.remote_open};EndpointState.prototype.has_settled=function(){return
 
this.open_requests==0&&this.close_requests==0};EndpointState.prototype.need_open=function(){if(this.open_requests>0){this.open_requests--;return
 true}else{return 
false}};EndpointState.prototype.need_close=function(){if(this.close_requests>0){this.close_requests--;return
 true}else{return 
false}};module.exports=EndpointState},{}],3:[function(require,module,exports){"use
 strict";var types=require("./types.js");var frames={};var 
by_descriptor={};frames.read_header=function(buffer){var offset=4;var 
header={};var name=buffer.toString("ascii",0,offset);if(name!=="AMQP"){throw 
Error("Invalid protocol header for AMQP 
"+name)}header.protocol_id=buffer.readUInt8(offset++);header.major=buffer.readUInt8(offset++);header.minor=buffer.readUInt8(offset++);header.revision=buffer.readUInt8(offset++);if(header.major!==1||header.minor!==0){throw
 Error("Unsupported AMQP version: "+JSON.stringi
 fy(header))}return header};frames.write_header=function(buffer,header){var 
offset=4;buffer.write("AMQP",0,offset,"ascii");buffer.writeUInt8(header.protocol_id,offset++);buffer.writeUInt8(header.major,offset++);buffer.writeUInt8(header.minor,offset++);buffer.writeUInt8(header.revision,offset++);return
 
8};frames.TYPE_AMQP=0;frames.TYPE_SASL=1;frames.read_frame=function(buffer){var 
reader=new types.Reader(buffer);var 
frame={};frame.size=reader.read_uint(4);if(reader.remaining<frame.size){return 
null}var doff=reader.read_uint(1);if(doff<2){throw Error("Invalid data offset, 
must be at least 2 was 
"+doff)}frame.type=reader.read_uint(1);if(frame.type===frames.TYPE_AMQP){frame.channel=reader.read_uint(2)}else
 if(frame.type===frames.TYPE_SASL){reader.skip(2)}else{throw Error("Unknown 
frame type 
"+frame.type)}if(doff>1){reader.skip(doff*4-8)}if(reader.remaining()){frame.performative=reader.read();var
 
c=by_descriptor[frame.performative.descriptor.value];if(c){frame.performative=new
 c(frame.per
 
formative.value)}if(reader.remaining()){frame.payload=reader.read_bytes(reader.remaining())}}return
 frame};frames.write_frame=function(frame){var writer=new 
types.Writer;writer.skip(4);writer.write_uint(2,1);writer.write_uint(frame.type,1);if(frame.type===frames.TYPE_AMQP){writer.write_uint(frame.channel,2)}else
 if(frame.type===frames.TYPE_SASL){writer.write_uint(0,2)}else{throw 
Error("Unknown frame type 
"+frame.type)}if(frame.performative){writer.write(frame.performative);if(frame.payload){writer.write_bytes(frame.payload)}}var
 buffer=writer.toBuffer();buffer.writeUInt32BE(buffer.length,0);return 
buffer};frames.amqp_frame=function(channel,performative,payload){return{channel:channel||0,type:frames.TYPE_AMQP,performative:performative,payload:payload}};frames.sasl_frame=function(performative){return{channel:0,type:frames.TYPE_SASL,performative:performative}};function
 define_frame(type,def){var 
c=types.define_composite(def);frames[def.name]=c.create;by_descriptor[Number(c.descriptor.n
 umeric).toString(10)]=c;by_descriptor[c.descriptor.symbolic]=c}var 
open={name:"open",code:16,fields:[{name:"container_id",type:"string",mandatory:true},{name:"hostname",type:"string"},{name:"max_frame_size",type:"uint",default_value:4294967295},{name:"channel_max",type:"ushort",default_value:65535},{name:"idle_time_out",type:"uint"},{name:"outgoing_locales",type:"symbol",multiple:true},{name:"incoming_locales",type:"symbol",multiple:true},{name:"offered_capabilities",type:"symbol",multiple:true},{name:"desired_capabilities",type:"symbol",multiple:true},{name:"properties",type:"symbolic_map"}]};var
 
begin={name:"begin",code:17,fields:[{name:"remote_channel",type:"ushort"},{name:"next_outgoing_id",type:"uint",mandatory:true},{name:"incoming_window",type:"uint",mandatory:true},{name:"outgoing_window",type:"uint",mandatory:true},{name:"handle_max",type:"uint",default_value:"4294967295"},{name:"offered_capabilities",type:"symbol",multiple:true},{name:"desired_capabilities",type:"symbol",m
 ultiple:true},{name:"properties",type:"symbolic_map"}]};var 
attach={name:"attach",code:18,fields:[{name:"name",type:"string",mandatory:true},{name:"handle",type:"uint",mandatory:true},{name:"role",type:"boolean",mandatory:true},{name:"snd_settle_mode",type:"ubyte",default_value:2},{name:"rcv_settle_mode",type:"ubyte",default_value:0},{name:"source",type:"*"},{name:"target",type:"*"},{name:"unsettled",type:"map"},{name:"incomplete_unsettled",type:"boolean",default_value:false},{name:"initial_delivery_count",type:"uint"},{name:"max_message_size",type:"ulong"},{name:"offered_capabilities",type:"symbol",multiple:true},{name:"desired_capabilities",type:"symbol",multiple:true},{name:"properties",type:"symbolic_map"}]};var
 
flow={name:"flow",code:19,fields:[{name:"next_incoming_id",type:"uint"},{name:"incoming_window",type:"uint",mandatory:true},{name:"next_outgoing_id",type:"uint",mandatory:true},{name:"outgoing_window",type:"uint",mandatory:true},{name:"handle",type:"uint"},{name:"deliver
 
y_count",type:"uint"},{name:"link_credit",type:"uint"},{name:"available",type:"uint"},{name:"drain",type:"boolean",default_value:false},{name:"echo",type:"boolean",default_value:false},{name:"properties",type:"symbolic_map"}]};var
 
transfer={name:"transfer",code:20,fields:[{name:"handle",type:"uint",mandatory:true},{name:"delivery_id",type:"uint"},{name:"delivery_tag",type:"binary"},{name:"message_format",type:"uint"},{name:"settled",type:"boolean"},{name:"more",type:"boolean",default_value:false},{name:"rcv_settle_mode",type:"ubyte"},{name:"state",type:"delivery_state"},{name:"resume",type:"boolean",default_value:false},{name:"aborted",type:"boolean",default_value:false},{name:"batchable",type:"boolean",default_value:false}]};var
 
disposition={name:"disposition",code:21,fields:[{name:"role",type:"boolean",mandatory:true},{name:"first",type:"uint",mandatory:true},{name:"last",type:"uint"},{name:"settled",type:"boolean",default_value:false},{name:"state",type:"*"},{name:"batchable",typ
 e:"boolean",default_value:false}]};var 
detach={name:"detach",code:22,fields:[{name:"handle",type:"uint",mandatory:true},{name:"closed",type:"boolean",default_value:false},{name:"error",type:"error"}]};var
 end={name:"end",code:23,fields:[{name:"error",type:"error"}]};var 
close={name:"close",code:24,fields:[{name:"error",type:"error"}]};define_frame(frames.TYPE_AMQP,open);define_frame(frames.TYPE_AMQP,begin);define_frame(frames.TYPE_AMQP,attach);define_frame(frames.TYPE_AMQP,flow);define_frame(frames.TYPE_AMQP,transfer);define_frame(frames.TYPE_AMQP,disposition);define_frame(frames.TYPE_AMQP,detach);define_frame(frames.TYPE_AMQP,end);define_frame(frames.TYPE_AMQP,close);var
 
sasl_mechanisms={name:"sasl_mechanisms",code:64,fields:[{name:"sasl_server_mechanisms",type:"symbol",multiple:true,mandatory:true}]};var
 
sasl_init={name:"sasl_init",code:65,fields:[{name:"mechanism",type:"symbol",mandatory:true},{name:"initial_response",type:"binary"},{name:"hostname",type:"string"}]};var
 sasl_chal
 
lenge={name:"sasl_challenge",code:66,fields:[{name:"challenge",type:"binary",mandatory:true}]};var
 
sasl_response={name:"sasl_response",code:67,fields:[{name:"response",type:"binary",mandatory:true}]};var
 
sasl_outcome={name:"sasl_outcome",code:68,fields:[{name:"code",type:"ubyte",mandatory:true},{name:"additional_data",type:"binary"}]};define_frame(frames.TYPE_SASL,sasl_mechanisms);define_frame(frames.TYPE_SASL,sasl_init);define_frame(frames.TYPE_SASL,sasl_challenge);define_frame(frames.TYPE_SASL,sasl_response);define_frame(frames.TYPE_SASL,sasl_outcome);module.exports=frames},{"./types.js":12}],4:[function(require,module,exports){(function(Buffer){"use
 strict";var frames=require("./frames.js");var log=require("./log.js");var 
message=require("./message.js");var terminus=require("./terminus.js");var 
types=require("./types.js");var EndpointState=require("./endpoint.js");var 
FlowController=function(window){this.window=window};FlowController.prototype.update=function(context){var
 delta=t
 his.window-context.receiver.credit;context.receiver.flow(delta)};function 
auto_settle(context){context.delivery.settled=true}function 
auto_accept(context){context.delivery.update(undefined,message.accepted().described())}function
 
LinkError(message,condition,link){Error.call(this);Error.captureStackTrace(this,this.constructor);this.message=message;this.condition=condition;this.description=message;this.link=link}require("util").inherits(LinkError,Error);var
 EventEmitter=require("events").EventEmitter;var 
link=Object.create(EventEmitter.prototype);link.dispatch=function(name,context){log.events("Link
 got event: 
"+name);EventEmitter.prototype.emit.apply(this.observers,arguments);if(this.listeners(name).length){EventEmitter.prototype.emit.apply(this,arguments);return
 true}else{return 
this.session.dispatch.apply(this.session,arguments)}};link.set_source=function(fields){this.local.attach.source=terminus.source(fields).described()};link.set_target=function(fields){this.local.attach.target=
 
terminus.target(fields).described()};link.attach=function(){if(this.state.open()){this.connection._register()}};link.open=link.attach;link.detach=function(){this.local.detach.closed=false;if(this.state.close()){this.connection._register()}};link.close=function(error){if(error)this.local.detach.error=error;this.local.detach.closed=true;if(this.state.close()){this.connection._register()}};link.is_open=function(){return
 this.session.is_open()&&this.state.is_open()};link.is_closed=function(){return 
this.session.is_closed()||this.state.is_closed()};link._process=function(){do{if(this.state.need_open()){this.session.output(this.local.attach.described())}if(this.issue_flow){this.session._write_flow(this);this.issue_flow=false}if(this.state.need_close()){this.session.output(this.local.detach.described())}}while(!this.state.has_settled())};link.on_attach=function(frame){if(this.state.remote_opened()){if(!this.remote.handle){this.remote.handle=frame.handle}frame.performative.source=terminus.u
 
nwrap(frame.performative.source);frame.performative.target=terminus.unwrap(frame.performative.target);this.remote.attach=frame.performative;this.open();this.dispatch(this.is_receiver()?"receiver_open":"sender_open",this._context())}else{throw
 Error("Attach already 
received")}};link.prefix_event=function(event){return(this.local.attach.role?"receiver_":"sender_")+event};link.on_detach=function(frame){if(this.state.remote_closed()){this.remote.detach=frame.performative;this.close();var
 error=this.remote.detach.error;if(error){var 
handled=this.dispatch(this.prefix_event("error"),this._context());handled=this.dispatch(this.prefix_event("close"),this._context())||handled;if(!handled){EventEmitter.prototype.emit.call(this.connection.container,"error",new
 
LinkError(error.description,error.condition,this))}}else{this.dispatch(this.prefix_event("close"),this._context())}}else{throw
 Error("Detach already received")}};function 
is_internal(name){switch(name){case"name":case"handle":case"role":c
 ase"initial_delivery_count":return true;default:return false}}var 
aliases=["snd_settle_mode","rcv_settle_mode","source","target","max_message_size","offered_capabilities","desired_capabilities","properties"];function
 remote_property_shortcut(name){return function(){return 
this.remote.attach?this.remote.attach[name]:undefined}}link.init=function(session,name,local_handle,opts,is_receiver){this.session=session;this.connection=session.connection;this.name=name;this.options=opts===undefined?{}:opts;this.state=new
 
EndpointState;this.issue_flow=false;this.local={handle:local_handle};this.local.attach=frames.attach({handle:local_handle,name:name,role:is_receiver});for(var
 f in 
this.local.attach){if(!is_internal(f)&&this.options[f]!==undefined){this.local.attach[f]=this.options[f]}}this.local.detach=frames.detach({handle:local_handle,closed:true});this.remote={handle:undefined};this.delivery_count=0;this.credit=0;this.observers=new
 EventEmitter;for(var i in aliases){var f=aliases[i];Object.
 
defineProperty(this,f,{get:remote_property_shortcut(f)})}Object.defineProperty(this,"error",{get:function(){return
 
this.remote.detach?this.remote.detach.error:undefined}})};link.reset=function(){this.state.disconnected();this.remote={handle:undefined};this.delivery_count=0;this.credit=0};link.has_credit=function(){return
 this.credit>0};link.is_receiver=function(){return 
this.local.attach.role};link._context=function(c){var 
context=c?c:{};if(this.is_receiver()){context.receiver=this}else{context.sender=this}return
 
this.session._context(context)};link.get_option=function(name,default_value){if(this.options[name]!==undefined)return
 this.options[name];else return 
this.session.get_option(name,default_value)};var 
Sender=function(session,name,local_handle,opts){this.init(session,name,local_handle,opts,false);this._draining=false;this._drained=false;this.local.attach.initial_delivery_count=0;this.tag=0;if(this.get_option("autosettle",true)){this.observers.on("settled",auto_settle)}var
 sende
 
r=this;if(this.get_option("treat_modified_as_released",true)){this.observers.on("modified",function(context){sender.dispatch("released",context)})}};Sender.prototype=Object.create(link);Sender.prototype.constructor=Sender;Sender.prototype._get_drain=function(){if(this._draining&&this._drained&&this.credit){while(this.credit){++this.delivery_count;--this.credit}return
 true}else{return 
false}};Sender.prototype.set_drained=function(drained){this._drained=drained;if(this._draining&&this._drained){this.issue_flow=true}};Sender.prototype.next_tag=function(){return
 new Buffer(new 
String(this.tag++))};Sender.prototype.sendable=function(frame){return 
this.credit&&this.session.outgoing.available()};Sender.prototype.on_flow=function(frame){var
 
flow=frame.performative;this.credit=flow.delivery_count+flow.link_credit-this.delivery_count;this._draining=flow.drain;this._drained=this.credit>0;if(this.is_open()){this.dispatch("sender_flow",this._context());if(this._draining){this.dispatch("sender_dr
 
aining",this._context())}if(this.sendable()){this.dispatch("sendable",this._context())}}};Sender.prototype.on_transfer=function(frame){throw
 Error("got transfer on sending 
link")};Sender.prototype.send=function(msg,tag){var 
delivery=this.session.send(this,tag?tag:this.next_tag(),message.encode(msg),0);if(this.local.attach.snd_settle_mode===1){delivery.settled=true}return
 delivery};var 
Receiver=function(session,name,local_handle,opts){this.init(session,name,local_handle,opts,true);this.drain=false;this.set_credit_window(this.get_option("credit_window",100));if(this.get_option("autoaccept",true)){this.observers.on("message",auto_accept)}};Receiver.prototype=Object.create(link);Receiver.prototype.constructor=Receiver;Receiver.prototype.on_flow=function(frame){this.dispatch("receiver_flow",this._context());if(frame.performative.drain){if(frame.performative.link_credit>0)console.log("ERROR:
 received flow with drain set, but non zero credit");else 
this.dispatch("receiver_drained",this._co
 
ntext())}};Receiver.prototype.flow=function(credit){if(credit>0){this.credit+=credit;this.issue_flow=true;this.connection._register()}};Receiver.prototype.add_credit=Receiver.prototype.flow;Receiver.prototype._get_drain=function(){return
 
this.drain};Receiver.prototype.set_credit_window=function(credit_window){if(credit_window>0){var
 flow_controller=new FlowController(credit_window);var 
listener=flow_controller.update.bind(flow_controller);this.observers.on("message",listener);this.observers.on("receiver_open",listener)}};module.exports={Sender:Sender,Receiver:Receiver}}).call(this,require("buffer").Buffer)},{"./endpoint.js":2,"./frames.js":3,"./log.js":5,"./message.js":6,"./terminus.js":10,"./types.js":12,buffer:16,events:20,util:30}],5:[function(require,module,exports){"use
 strict";var 
debug=require("debug");module.exports={frames:debug("rhea:frames"),raw:debug("rhea:raw"),reconnect:debug("rhea:reconnect"),events:debug("rhea:events"),message:debug("rhea:message"),flow:debug("rhea:f
 
low"),io:debug("rhea:io")}},{debug:31}],6:[function(require,module,exports){"use
 strict";var log=require("./log.js");
-var types=require("./types.js");var by_descriptor={};var unwrappers={};var 
wrappers=[];var message={};function 
define_section(descriptor,unwrap,wrap){unwrap.descriptor=descriptor;unwrappers[descriptor.symbolic]=unwrap;unwrappers[Number(descriptor.numeric).toString(10)]=unwrap;if(wrap){wrappers.push(wrap)}}function
 define_composite_section(def){var 
c=types.define_composite(def);message[def.name]=c.create;by_descriptor[Number(c.descriptor.numeric).toString(10)]=c;by_descriptor[c.descriptor.symbolic]=c;var
 unwrap=function(msg,section){msg[def.name]=new c(section.value)};var 
wrap=function(sections,msg){if(msg[def.name]){if(msg[def.name].described){sections.push(msg[def.name].described())}else{sections.push(c.create(msg[def.name]).described())}}};define_section(c.descriptor,unwrap,wrap)}function
 define_map_section(def){var 
descriptor={numeric:def.code};descriptor.symbolic="amqp:"+def.name.replace(/_/g,"-")+":map";var
 unwrap=function(msg,section){msg[def.name]=types.unwrap(section)};var w
 
rap=function(sections,msg){if(msg[def.name]){sections.push(types.described(types.wrap_ulong(descriptor.numeric),types.wrap_map(msg[def.name])))}};define_section(descriptor,unwrap,wrap)}define_composite_section({name:"header",code:112,fields:[{name:"durable",type:"boolean",default_value:false},{name:"priority",type:"ubyte",default_value:4},{name:"ttl",type:"uint"},{name:"first_acquirer",type:"boolean",default_value:false},{name:"delivery_count",type:"uint",default_value:0}]});define_map_section({name:"delivery_annotations",code:113});define_map_section({name:"message_annotations",code:114});define_composite_section({name:"properties",code:115,fields:[{name:"message_id",type:"message_id"},{name:"user_id",type:"binary"},{name:"to",type:"string"},{name:"subject",type:"string"},{name:"reply_to",type:"string"},{name:"correlation_id",type:"message_id"},{name:"content_type",type:"symbol"},{name:"content_encoding",type:"symbol"},{name:"absolute_expiry_time",type:"timestamp"},{name:"creation_
 
time",type:"timestamp"},{name:"group_id",type:"string"},{name:"group_sequence",type:"uint"},{name:"reply_to_group_id",type:"string"}]});define_map_section({name:"application_properties",code:116});define_section({numeric:119,symbolic:"amqp:value:*"},function(msg,section){msg.body=types.unwrap(section)},function(sections,msg){sections.push(types.described(types.wrap_ulong(119),types.wrap(msg.body)))});define_map_section({name:"footer",code:120});function
 reverse_lookup(map){var reversed={};for(var key in map){var 
values=map[key];for(var i in values){reversed[values[i]]=key}}return 
reversed}var 
special_sections={properties:["message_id","user_id","to","subject","reply_to","correlation_id","content_type","content_encoding","absolute_expiry_time","creation_time","group_id","group_sequence","reply_to_group_id"],header:["durable","priority","ttl","first_acquirer","delivery_count"]};var
 special_fields=reverse_lookup(special_sections);var 
section_names=["header","delivery_annotations","mess
 
age_annotations","properties","application_properties","body","footer"];function
 copy(src,tgt){for(var k in src){var v=src[k];if(typeof 
v==="object"){copy(v,tgt[k])}else{tgt[k]=v}}}function 
add_property_shortcut(o,group,name){Object.defineProperty(o,name,{get:function(){return
 
this[group]?this[group][name]:undefined},set:function(v){if(this[group]===undefined){this[group]={}}this[group][name]=v}})}function
 create_message(m){var msg={toJSON:function(){var o={};for(var i in 
section_names){var key=section_names[i];if(typeof 
this[key]==="function")continue;var 
fields=special_sections[key];if(fields){for(var j in 
fields){if(this[fields[j]]!==undefined){if(o[key]===undefined)o[key]={};o[key][fields[j]]=this[fields[j]]}}}else
 if(this[key]){o[key]=this[key]}}return o},inspect:function(){return 
JSON.stringify(this.toJSON())},toString:function(){return 
JSON.stringify(this.toJSON())}};for(var field in 
special_fields){add_property_shortcut(msg,special_fields[field],field)}if(m)copy(m,msg);retur
 n msg}function massage(msg){var out=undefined;for(var key in msg){if(typeof 
msg[key]!=="function"&&section_names.indexOf(key)<0){if(out===undefined)out={};var
 
group=special_fields[key]||"application_properties";if(out[group]===undefined){out[group]={}}out[group][key]=msg[key]}else{if(out!==undefined){out[key]=msg[key]}}}return
 out||msg}message.encode=function(obj){var sections=[];var 
msg=massage(obj);wrappers.forEach(function(wrapper_fn){wrapper_fn(sections,msg)});var
 writer=new types.Writer;for(var 
i=0;i<sections.length;i++){log.message("Encoding section "+(i+1)+" of 
"+sections.length+": "+sections[i]);writer.write(sections[i])}var 
data=writer.toBuffer();log.message("encoded "+data.length+" bytes");return 
data};message.decode=function(buffer){var msg=create_message();var reader=new 
types.Reader(buffer);while(reader.remaining()){var 
s=reader.read();log.message("decoding section: "+JSON.stringify(s)+" of type: 
"+JSON.stringify(s.descriptor));if(s.descriptor){var unwrap=unwrappers[s.d
 escriptor.value];if(unwrap){unwrap(msg,s)}else{console.log("WARNING: did not 
recognise message section with descriptor 
"+s.descriptor)}}else{console.log("WARNING: expected described message section 
got "+JSON.stringify(s))}}if(msg.application_properties){for(var key in 
msg.application_properties){add_property_shortcut(msg,"application_properties",key)}}return
 msg};var outcomes={};function define_outcome(def){var 
c=types.define_composite(def);c.composite_type=def.name;message[def.name]=c.create;outcomes[Number(c.descriptor.numeric).toString(10)]=c;outcomes[c.descriptor.symbolic]=c;message["is_"+def.name]=function(o){if(o&&o.descriptor){var
 c=outcomes[o.descriptor.value];if(c){return 
c.descriptor.numeric==def.code}}return 
false}}message.unwrap_outcome=function(outcome){if(outcome&&outcome.descriptor){var
 c=outcomes[outcome.descriptor.value];if(c){return new 
c(types.unwrap(outcome))}}console.log("unrecognised outcome: 
"+JSON.stringify(outcome));return outcome};message.are_outcomes_equi
 valent=function(a,b){if(a===undefined&&b===undefined)return true;else 
if(a===undefined||b===undefined)return false;else return 
a.descriptor.value==b.descriptor.value&&JSON.stringify(a)==JSON.stringify(b)};define_outcome({name:"received",code:35,fields:[{name:"section_number",type:"uint",mandatory:true},{name:"section_offset",type:"ulong",mandatory:true}]});define_outcome({name:"accepted",code:36,fields:[]});define_outcome({name:"rejected",code:37,fields:[{name:"error",type:"error"}]});define_outcome({name:"released",code:38,fields:[]});define_outcome({name:"modified",code:39,fields:[{name:"delivery_failed",type:"boolean"},{name:"undeliverable_here",type:"boolean"},{name:"message_annotations",type:"map"}]});module.exports=message},{"./log.js":5,"./types.js":12}],7:[function(require,module,exports){"use
 strict";var url=require("url");var 
simple_id_generator={counter:1,next:function(){return this.counter++}};var 
Client=function(container,address){var u=url.parse(address);this.connectio
 
n=container.connect({host:u.hostname,port:u.port});this.connection.on("message",this._response.bind(this));this.connection.on("receiver_open",this._ready.bind(this));this.sender=this.connection.attach_sender(u.path.substr(1));this.receiver=this.connection.attach_receiver({source:{dynamic:true}});this.id_generator=simple_id_generator;this.pending=[];this.outstanding={}};Client.prototype._request=function(id,name,args,callback){var
 
request={properties:{}};request.properties.subject=name;request.body=args;request.properties.message_id=id;request.properties.reply_to=this.receiver.remote.attach.source.address;this.outstanding[id]=callback;this.sender.send(request)};Client.prototype._response=function(context){var
 id=context.message.properties.correlation_id;var 
callback=this.outstanding[id];if(callback){if(context.message.properties.subject==="ok"){callback(context.message.body)}else{callback(undefined,{name:context.message.properties.subject,description:context.message.body})}}else{cons
 ole.log("no request pending for "+id+", ignoring 
response")}};Client.prototype._ready=function(context){this._process_pending()};Client.prototype._process_pending=function(){for(var
 i=0;i<this.pending.length;i++){var 
r=this.pending[i];this._request(r.id,r.name,r.args,r.callback)}this.pending=[]};Client.prototype.call=function(name,args,callback){var
 
id=this.id_generator.next();if(this.receiver.is_open()&&this.pending.length===0){this._request(id,name,args,callback)}else{this.pending.push({name:name,args:args,callback:callback,id:id})}};Client.prototype.close=function(){this.receiver.close();this.sender.close();this.connection.close()};Client.prototype.define=function(name){this[name]=function(args,callback){this.call(name,args,callback)}};var
 
Cache=function(ttl,purged){this.ttl=ttl;this.purged=purged;this.entries={};this.timeout=undefined};Cache.prototype.clear=function(){if(this.timeout)clearTimeout(this.timeout);this.entries={}};Cache.prototype.put=function(key,value){this.entries
 
[key]={value:value,last_accessed:Date.now()};if(!this.timeout)this.timeout=setTimeout(this.purge.bind(this),this.ttl)};Cache.prototype.get=function(key){var
 entry=this.entries[key];if(entry){entry.last_accessed=Date.now();return 
entry.value}else{return undefined}};Cache.prototype.purge=function(){var 
now=Date.now();var expired=[];var live=0;for(var k in 
this.entries){if(now-this.entries[k].last_accessed>=this.ttl){expired.push(k)}else{live++}}for(var
 i=0;i<expired.length;i++){var entry=this.entries[expired[i]];delete 
this.entries[expired[i]];this.purged(entry.value)}if(live&&!this.timeout){this.timeout=setTimeout(this.purge.bind(this),this.ttl)}};var
 LinkCache=function(factory,ttl){this.factory=factory;this.cache=new 
Cache(ttl,function(link){link.close()})};LinkCache.prototype.clear=function(){this.cache.clear()};LinkCache.prototype.get=function(address){var
 
link=this.cache.get(address);if(link===undefined){link=this.factory(address);this.cache.put(address,link)}return
 link};var Ser
 ver=function(container,address,options){this.options=options||{};var 
u=url.parse(address);this.connection=container.connect({host:u.hostname,port:u.port});this.connection.on("connection_open",this._connection_open.bind(this));this.connection.on("message",this._request.bind(this));this.receiver=this.connection.attach_receiver(u.path.substr(1));this.callbacks={};this._send=undefined;this._clear=undefined};function
 match(desired,offered){if(offered){if(Array.isArray(offered)){return 
offered.indexOf(desired)>-1}else{return desired===offered}}else{return 
false}}Server.prototype._connection_open=function(context){if(match("ANONYMOUS-RELAY",this.connection.remote.open.offered_capabilities)){var
 
relay=this.connection.attach_sender({target:{}});this._send=function(msg){relay.send(msg)}}else{var
 cache=new 
LinkCache(this.connection.attach_sender.bind(this.connection),this.options.cache_ttl||6e4);this._send=function(msg){var
 s=cache.get(msg.properties.to);if(s)s.send(msg)};this._clear=function(
 ){cache.clear()}}};Server.prototype._respond=function(response){var 
server=this;return 
function(result,error){if(error){response.properties.subject=error.name||"error";response.body=error.description||error}else{response.properties.subject="ok";response.body=result}server._send(response)}};Server.prototype._request=function(context){var
 request=context.message;var 
response={properties:{}};response.properties.to=request.properties.reply_to;response.properties.correlation_id=request.properties.message_id;var
 
callback=this.callbacks[request.properties.subject];if(callback){callback(request.body,this._respond(response))}else{response.properties.subject="bad-method";response.body="Unrecognised
 method 
"+request.properties.subject;this._send(response)}};Server.prototype.bind_sync=function(f,name){this.callbacks[name||f.name]=function(args,callback){var
 
result=f(args);callback(result)}};Server.prototype.bind=function(f,name){this.callbacks[name||f.name]=f};Server.prototype.close=function(){
 
if(this._clear)this._clear();this.receiver.close();this.connection.close()};module.exports={server:function(container,address,options){return
 new 
Server(container,address,options)},client:function(connection,address){return 
new 
Client(connection,address)}}},{url:27}],8:[function(require,module,exports){(function(Buffer){"use
 strict";var frames=require("./frames.js");var log=require("./log.js");var 
Transport=require("./transport.js");var 
sasl_codes={OK:0,AUTH:1,SYS:2,SYS_PERM:3,SYS_TEMP:4};var 
SASL_PROTOCOL_ID=3;function intersection(lista,listb){return 
lista.filter(function(a){return listb.indexOf(a)>=0})}function 
extract(buffer){var results=[];var start=0;var 
i=0;while(i<buffer.length){if(buffer[i]===0){if(i>start)results.push(buffer.toString("utf8",start,i));else
 
results.push(null);start=++i}else{++i}}if(i>start)results.push(buffer.toString("utf8",start,i));else
 results.push(null);return results}var 
PlainServer=function(callback){this.callback=callback;this.outcome=undefined;this.
 username=undefined};PlainServer.prototype.start=function(response){var 
fields=extract(response);if(fields.length!==3){this.connection.sasl_failed("Unexpected
 response in PLAIN, got "+fields.length+" fields, expected 
3")}if(this.callback(fields[1],fields[2])){this.outcome=true;this.username=fields[1]}else{this.outcome=false}};var
 
PlainClient=function(username,password){this.username=username;this.password=password};PlainClient.prototype.start=function(){var
 response=new 
Buffer(1+this.username.length+1+this.password.length);response.writeUInt8(0,0);response.write(this.username,1);response.writeUInt8(0,1+this.username.length);response.write(this.password,1+this.username.length+1);return
 response};var 
AnonymousServer=function(){this.outcome=undefined;this.username=undefined};AnonymousServer.prototype.start=function(response){this.outcome=true;this.username=response?response.toString("utf8"):"anonymous"};var
 
AnonymousClient=function(name){this.username=name?name:"anonymous"};AnonymousCli
 ent.prototype.start=function(){var response=new 
Buffer(1+this.username.length);response.writeUInt8(0,0);response.write(this.username,1);return
 response};var 
ExternalServer=function(){this.outcome=undefined;this.username=undefined};ExternalServer.prototype.start=function(response){this.outcome=true};var
 
ExternalClient=function(){this.username=undefined};ExternalClient.prototype.start=function(){return
 null};var 
SaslServer=function(connection,mechanisms){this.connection=connection;this.transport=new
 
Transport(connection.amqp_transport.identifier,SASL_PROTOCOL_ID,frames.TYPE_SASL,this);this.next=connection.amqp_transport;this.mechanisms=mechanisms;this.mechanism=undefined;this.outcome=undefined;this.username=undefined;var
 
mechlist=Object.getOwnPropertyNames(mechanisms);this.transport.encode(frames.sasl_frame(frames.sasl_mechanisms({sasl_server_mechanisms:mechlist}).described()))};SaslServer.prototype.do_step=function(challenge){if(this.mechanism.outcome===undefined){this.transport.enco
 
de(frames.sasl_frame(frames.sasl_challenge({challenge:challenge}).described()))}else{this.outcome=this.mechanism.outcome?sasl_codes.OK:sasl_codes.AUTH;this.transport.encode(frames.sasl_frame(frames.sasl_outcome({code:this.outcome}).described()));if(this.outcome===sasl_codes.OK){this.username=this.mechanism.username;this.transport.write_complete=true;this.transport.read_complete=true}}};SaslServer.prototype.on_sasl_init=function(frame){var
 f=this.mechanisms[frame.performative.mechanism];if(f){this.mechanism=f();var 
challenge=this.mechanism.start(frame.performative.initial_response);this.do_step(challenge)}else{this.outcome=sasl_codes.AUTH;this.transport.encode(frames.sasl_frame(frames.sasl_outcome({code:this.outcome}).described()))}};SaslServer.prototype.on_sasl_response=function(frame){this.do_step(this.mechanism.step(frame.performative.response))};SaslServer.prototype.has_writes_pending=function(){return
 this.transport.has_writes_pending()||this.next.has_writes_pending()};SaslServe
 
r.prototype.write=function(socket){if(this.transport.write_complete&&this.transport.pending.length===0){return
 this.next.write(socket)}else{return 
this.transport.write(socket)}};SaslServer.prototype.read=function(buffer){if(this.transport.read_complete){return
 this.next.read(buffer)}else{return this.transport.read(buffer)}};var 
SaslClient=function(connection,mechanisms){this.connection=connection;this.transport=new
 
Transport(connection.amqp_transport.identifier,SASL_PROTOCOL_ID,frames.TYPE_SASL,this);this.next=connection.amqp_transport;this.mechanisms=mechanisms;this.mechanism=undefined;this.mechanism_name=undefined;this.failed=false};SaslClient.prototype.on_sasl_mechanisms=function(frame){for(var
 
i=0;this.mechanism===undefined&&i<frame.performative.sasl_server_mechanisms.length;i++){var
 mech=frame.performative.sasl_server_mechanisms[i];var 
f=this.mechanisms[mech];if(f){this.mechanism=f();this.mechanism_name=mech}}if(this.mechanism){var
 response=this.mechanism.start();this.transport
 
.encode(frames.sasl_frame(frames.sasl_init({mechanism:this.mechanism_name,initial_response:response}).described()))}else{this.failed=true;this.connection.sasl_failed("No
 suitable mechanism; server supports 
"+frame.performative.sasl_server_mechanisms)}};SaslClient.prototype.on_sasl_challenge=function(frame){var
 
response=this.mechanism.step(frame.performative.challenge);this.transport.encode(frames.sasl_frame(frames.sasl_response({response:response}).described()))};SaslClient.prototype.on_sasl_outcome=function(frame){switch(frame.performative.code){case
 
sasl_codes.OK:this.transport.read_complete=true;this.transport.write_complete=true;break;default:this.transport.write_complete=true;this.connection.sasl_failed("Failed
 to authenticate: 
"+frame.performative.code)}};SaslClient.prototype.has_writes_pending=function(){return
 
this.transport.has_writes_pending()||this.next.has_writes_pending()};SaslClient.prototype.write=function(socket){if(this.transport.write_complete){return
 this.next.wri
 te(socket)}else{return 
this.transport.write(socket)}};SaslClient.prototype.read=function(buffer){if(this.transport.read_complete){return
 this.next.read(buffer)}else{return this.transport.read(buffer)}};var 
default_server_mechanisms={enable_anonymous:function(){this["ANONYMOUS"]=function(){return
 new 
AnonymousServer}},enable_plain:function(callback){this["PLAIN"]=function(){return
 new PlainServer(callback)}}};var 
default_client_mechanisms={enable_anonymous:function(name){this["ANONYMOUS"]=function(){return
 new 
AnonymousClient(name)}},enable_plain:function(username,password){this["PLAIN"]=function(){return
 new 
PlainClient(username,password)}},enable_external:function(){this["EXTERNAL"]=function(){return
 new 
ExternalClient}}};module.exports={Client:SaslClient,Server:SaslServer,server_mechanisms:function(){return
 Object.create(default_server_mechanisms)},client_mechanisms:function(){return 
Object.create(default_client_mechanisms)},server_add_external:function(mechs){mechs["EXTERNAL"]=fu
 nction(){return new ExternalServer};return 
mechs}}}).call(this,require("buffer").Buffer)},{"./frames.js":3,"./log.js":5,"./transport.js":11,buffer:16}],9:[function(require,module,exports){(function(Buffer){"use
 strict";var frames=require("./frames.js");var link=require("./link.js");var 
log=require("./log.js");var message=require("./message.js");var 
types=require("./types.js");var util=require("./util.js");var 
EndpointState=require("./endpoint.js");var 
EventEmitter=require("events").EventEmitter;var 
CircularBuffer=function(capacity){this.capacity=capacity;this.size=0;this.head=0;this.tail=0;this.entries=[]};CircularBuffer.prototype.available=function(){return
 
this.capacity-this.size};CircularBuffer.prototype.push=function(o){if(this.size<this.capacity){this.entries[this.tail]=o;this.tail=(this.tail+1)%this.capacity;this.size++}else{throw
 Error("circular buffer overflow: head="+this.head+" tail="+this.tail+" 
size="+this.size+" capacity="+this.capacity)}};CircularBuffer.prototype.pop_i
 f=function(f){var 
count=0;while(this.size&&f(this.entries[this.head])){this.entries[this.head]=undefined;this.head=(this.head+1)%this.capacity;this.size--;count++}return
 count};CircularBuffer.prototype.by_id=function(id){if(this.size>0){var 
gap=id-this.entries[this.head].id;if(gap<this.size){return 
this.entries[(this.head+gap)%this.capacity]}}return 
undefined};CircularBuffer.prototype.get_head=function(id){return 
this.size>0?this.entries[this.head]:undefined};function 
write_dispositions(deliveries){var first;var last;var next_id;for(var 
i=0;i<deliveries.length;i++){var 
delivery=deliveries[i];if(first===undefined){first=delivery;last=delivery;next_id=delivery.id}if(!message.are_outcomes_equivalent(last.state,delivery.state)||last.settled!==delivery.settled||next_id!==delivery.id){first.link.session.output(frames.disposition({role:first.link.is_receiver(),first:first.id,last:last.id,state:first.state,settled:first.settled}).described());first=delivery;last=delivery;next_id=delivery.id
 
}else{if(last.id!==delivery.id){last=delivery}next_id++}}if(first!==undefined&&last!==undefined){first.link.session.output(frames.disposition({role:first.link.is_receiver(),first:first.id,last:last.id,state:first.state,settled:first.settled}).described())}}var
 Outgoing=function(){this.deliveries=new 
CircularBuffer(2048);this.updated=[];this.pending_dispositions=[];this.next_delivery_id=0;this.next_pending_delivery=0;this.next_transfer_id=0;this.window=types.MAX_UINT;this.remote_next_transfer_id=undefined;this.remote_window=undefined};Outgoing.prototype.available=function(){return
 
this.deliveries.available()};Outgoing.prototype.send=function(sender,tag,data,format){var
 
d={id:this.next_delivery_id++,tag:tag,link:sender,data:data,format:format?format:0,sent:false,settled:false,state:undefined,remote_settled:false,remote_state:undefined};var
 
self=this;d.update=function(settled,state){self.update(d,settled,state)};this.deliveries.push(d);return
 d};Outgoing.prototype.on_begin=function(fie
 
lds){this.remote_window=fields.incoming_window};Outgoing.prototype.on_flow=function(fields){this.remote_next_transfer_id=fields.next_incoming_id;this.remote_window=fields.incoming_window};Outgoing.prototype.on_disposition=function(fields){var
 last=fields.last?fields.last:fields.first;for(var 
i=fields.first;i<=last;i++){var 
d=this.deliveries.by_id(i);if(d&&!d.remote_settled){var 
updated=false;if(fields.settled){d.remote_settled=fields.settled;updated=true}if(fields.state&&fields.state!==d.remote_state){d.remote_state=message.unwrap_outcome(fields.state);updated=true}if(updated){this.updated.push(d)}}}};Outgoing.prototype.update=function(delivery,settled,state){if(delivery){delivery.settled=settled;if(state!==undefined)delivery.state=state;if(!delivery.remote_settled){this.pending_dispositions.push(delivery)}delivery.link.connection._register()}};Outgoing.prototype.transfer_window=function(){if(this.remote_window){return
 this.remote_window-(this.next_transfer_id-this.remote_next_trans
 
fer_id)}};Outgoing.prototype.process=function(){while(this.next_pending_delivery<this.next_delivery_id){var
 
d=this.deliveries.by_id(this.next_pending_delivery);if(d){if(d.link.has_credit()){d.link.delivery_count++;d.transfers_required=1;if(this.transfer_window()>=d.transfers_required){this.next_transfer_id+=d.transfers_required;this.window-=d.transfers_required;d.link.session.output(frames.transfer({handle:d.link.local.handle,message_format:d.format,delivery_id:d.id,delivery_tag:d.tag,settled:d.settled}).described(),d.data);d.link.credit--;this.next_pending_delivery++}else{log.flow("Incoming
 window of peer preventing sending further transfers: 
remote_window="+this.remote_window+", 
remote_next_transfer_id="+this.remote_next_transfer_id+", 
next_transfer_id="+this.next_transfer_id);break}}else{log.flow("Link has no 
credit");break}}else{console.log("ERROR: Next pending delivery not found: 
"+this.next_pending_delivery);break}}for(var i=0;i<this.updated.length;i++){var 
d=this.updated[i];i
 
f(d.remote_state&&d.remote_state.constructor.composite_type){d.link.dispatch(d.remote_state.constructor.composite_type,d.link._context({delivery:d}))}if(d.remote_settled)d.link.dispatch("settled",d.link._context({delivery:d}))}this.updated=[];if(this.pending_dispositions.length){write_dispositions(this.pending_dispositions);this.pending_dispositions=[]}this.deliveries.pop_if(function(d){return
 d.settled&&d.remote_settled})};var Incoming=function(){this.deliveries=new 
CircularBuffer(2048);this.updated=[];this.next_transfer_id=0;this.next_delivery_id=undefined;this.window=2048;this.remote_next_transfer_id=undefined;this.remote_window=undefined};Incoming.prototype.update=function(delivery,settled,state){if(delivery){delivery.settled=settled;if(state!==undefined)delivery.state=state;if(!delivery.remote_settled){this.updated.push(delivery)}delivery.link.connection._register()}};Incoming.prototype.on_transfer=function(frame,receiver){this.next_transfer_id++;if(receiver.is_open()){if(this.
 
next_delivery_id===undefined){this.next_delivery_id=frame.performative.delivery_id}var
 current;var data;var 
last=this.deliveries.get_head();if(last&&last.incomplete){if(frame.performative.delivery_id!==undefined&&this.next_delivery_id!=frame.performative.delivery_id){throw
 Error("frame sequence error: delivery "+this.next_delivery_id+" not complete, 
got 
"+frame.performative.delivery_id)}current=last;data=Buffer.concat([current.data,frame.payload],current.data.size()+frame.payload.size())}else
 
if(this.next_delivery_id===frame.performative.delivery_id){current={id:frame.performative.delivery_id,tag:frame.performative.delivery_tag,link:receiver,settled:false,state:undefined,remote_settled:frame.performative.settled===undefined?false:frame.performative.settled,remote_state:frame.performative.state};var
 self=this;current.update=function(settled,state){var 
settled_=settled;if(settled_===undefined){settled_=receiver.local.attach.rcv_settle_mode!==1}self.update(current,settled_,state)};curr
 
ent.accept=function(){this.update(undefined,message.accepted().described())};current.release=function(params){if(params){this.update(undefined,message.modified(params).described())}else{this.update(undefined,message.released().described())}};current.reject=function(error){this.update(true,message.rejected({error:error}).described())};current.modified=function(params){this.update(true,message.modified(params).described())};this.deliveries.push(current);data=frame.payload}else{throw
 Error("frame sequence error: expected "+this.next_delivery_id+", got 
"+frame.performative.delivery_id)}current.incomplete=frame.performative.more;if(current.incomplete){current.data=data}else{receiver.credit--;receiver.delivery_count++;this.next_delivery_id++;receiver.dispatch("message",receiver._context({message:message.decode(data),delivery:current}))}}};Incoming.prototype.process=function(){if(this.updated.length>0){write_dispositions(this.updated);this.updated=[]}this.deliveries.pop_if(function(d){retu
 rn 
d.settled})};Incoming.prototype.on_begin=function(fields){this.remote_window=fields.outgoing_window};Incoming.prototype.on_flow=function(fields){this.remote_next_transfer_id=fields.next_outgoing_id;this.remote_window=fields.outgoing_window};Incoming.prototype.on_disposition=function(fields){var
 last=fields.last?fields.last:fields.first;for(var 
i=fields.first;i<=last;i++){var 
d=this.deliveries.by_id(i);if(d&&!d.remote_settled){var 
updated=false;if(fields.settled){d.remote_settled=fields.settled;d.link.dispatch("settled",d.link._context({delivery:d}))}}}};var
 
Session=function(connection,local_channel){this.connection=connection;this.outgoing=new
 Outgoing;this.incoming=new Incoming;this.state=new 
EndpointState;this.local={channel:local_channel,handles:{}};this.local.begin=frames.begin({next_outgoing_id:this.outgoing.next_transfer_id,incoming_window:this.incoming.window,outgoing_window:this.outgoing.window});this.local.end=frames.end();this.remote={handles:{}};this.links={};this.opti
 
ons={}};Session.prototype=Object.create(EventEmitter.prototype);Session.prototype.constructor=Session;Session.prototype.reset=function(){this.state.disconnected();this.outgoing=new
 Outgoing;this.incoming=new Incoming;this.remote={handles:{}};for(var l in 
this.links){this.links[l].reset()}};Session.prototype.dispatch=function(name,context){log.events("Session
 got event: 
"+name);if(this.listeners(name).length){EventEmitter.prototype.emit.apply(this,arguments);return
 true}else{return 
this.connection.dispatch.apply(this.connection,arguments)}};Session.prototype.output=function(frame,payload){this.connection._write_frame(this.local.channel,frame,payload)};Session.prototype.create_sender=function(name,opts){return
 
this.create_link(name,link.Sender,opts)};Session.prototype.create_receiver=function(name,opts){return
 this.create_link(name,link.Receiver,opts)};function 
attach(factory,args,remote_terminus){var opts=args?args:{};if(typeof 
args==="string"){opts={};opts[remote_terminus]=args}if(!
 opts.name)opts.name=util.generate_uuid();var l=factory(opts.name,opts);for(var 
t in{source:0,target:0}){if(opts[t]){if(typeof 
opts[t]==="string"){opts[t]={address:opts[t]}}l["set_"+t](opts[t])}}l.attach();return
 
l}Session.prototype.get_option=function(name,default_value){if(this.options[name]!==undefined)return
 this.options[name];else return 
this.connection.get_option(name,default_value)};Session.prototype.attach_sender=function(args){return
 
attach(this.create_sender.bind(this),args,"target")};Session.prototype.open_sender=Session.prototype.attach_sender;Session.prototype.attach_receiver=function(args){return
 
attach(this.create_receiver.bind(this),args,"source")};Session.prototype.open_receiver=Session.prototype.attach_receiver;Session.prototype.create_link=function(name,constructor,opts){var
 i=0;while(this.local.handles[i])i++;var l=new 
constructor(this,name,i,opts);this.links[name]=l;this.local.handles[i]=l;return 
l};Session.prototype.begin=function(){if(this.state.open()){this.co
 
nnection._register()}};Session.prototype.open=Session.prototype.begin;Session.prototype.end=function(error){if(error)this.local.end.error=error;if(this.state.close()){this.connection._register()}};Session.prototype.close=Session.prototype.end;Session.prototype.is_open=function(){return
 
this.connection.is_open()&&this.state.is_open()};Session.prototype.is_closed=function(){return
 
this.connection.is_closed()||this.state.is_closed()};Session.prototype._process=function(){do{if(this.state.need_open()){this.output(this.local.begin.described())}this.outgoing.process();this.incoming.process();for(var
 k in 
this.links){this.links[k]._process()}if(this.state.need_close()){this.output(this.local.end.described())}}while(!this.state.has_settled())};Session.prototype.send=function(sender,tag,data,format){var
 
d=this.outgoing.send(sender,tag,data,format);this.connection._register();return 
d};Session.prototype._write_flow=function(link){var 
fields={next_incoming_id:this.incoming.next_transfer_id,inc
 
oming_window:this.incoming.window,next_outgoing_id:this.outgoing.next_transfer_id,outgoing_window:this.outgoing.window};if(link){if(link._get_drain())fields.drain=true;fields.delivery_count=link.delivery_count;fields.handle=link.local.handle;fields.link_credit=link.credit}this.output(frames.flow(fields).described())};Session.prototype.on_begin=function(frame){if(this.state.remote_opened()){if(!this.remote.channel){this.remote.channel=frame.channel}this.remote.begin=frame.performative;this.outgoing.on_begin(frame.performative);this.incoming.on_begin(frame.performative);this.open();this.dispatch("session_open",this._context())}else{throw
 Error("Begin already 
received")}};Session.prototype.on_end=function(frame){if(this.state.remote_closed()){this.remote.end=frame.performative;this.close();this.dispatch("session_close",this._context())}else{throw
 Error("End already 
received")}};Session.prototype.on_attach=function(frame){var 
name=frame.performative.name;var link=this.links[name];if(!li
 
nk){link=frame.performative.role?this.create_sender(name):this.create_receiver(name)}this.remote.handles[frame.performative.handle]=link;
-link.on_attach(frame);link.remote.attach=frame.performative};Session.prototype.on_disposition=function(frame){if(frame.performative.role){log.events("Received
 disposition for outgoing 
transfers");this.outgoing.on_disposition(frame.performative)}else{log.events("Received
 disposition for incoming 
transfers");this.incoming.on_disposition(frame.performative)}this.connection._register()};Session.prototype.on_flow=function(frame){this.outgoing.on_flow(frame.performative);this.incoming.on_flow(frame.performative);if(frame.performative.handle!==undefined){this._get_link(frame).on_flow(frame)}this.connection._register()};Session.prototype._context=function(c){var
 context=c?c:{};context.session=this;return 
this.connection._context(context)};Session.prototype._get_link=function(frame){var
 handle=frame.performative.handle;var 
link=this.remote.handles[handle];if(!link){throw Error("Invalid handle 
"+handle)}return 
link};Session.prototype.on_detach=function(frame){this._get_link(frame).on_detach(f
 rame);var handle=frame.performative.handle;var 
link=this.remote.handles[handle];delete this.remote.handles[handle];delete 
this.local.handles[link.local.handle];delete 
this.links[link.name]};Session.prototype.on_transfer=function(frame){this.incoming.on_transfer(frame,this._get_link(frame))};module.exports=Session}).call(this,require("buffer").Buffer)},{"./endpoint.js":2,"./frames.js":3,"./link.js":4,"./log.js":5,"./message.js":6,"./types.js":12,"./util.js":13,buffer:16,events:20}],10:[function(require,module,exports){"use
 strict";var types=require("./types.js");var terminus={};var 
by_descriptor={};function define_terminus(def){var 
c=types.define_composite(def);terminus[def.name]=c.create;by_descriptor[Number(c.descriptor.numeric).toString(10)]=c;by_descriptor[c.descriptor.symbolic]=c}terminus.unwrap=function(field){if(field&&field.descriptor){var
 c=by_descriptor[field.descriptor.value];if(c){return new 
c(field.value)}else{console.log("Unknown terminus: "+field.descriptor)}}return 
nu
 
ll};define_terminus({name:"source",code:40,fields:[{name:"address",type:"string"},{name:"durable",type:"uint",default_value:0},{name:"expiry_policy",type:"symbol",default_value:"session-end"},{name:"timeout",type:"uint",default_value:0},{name:"dynamic",type:"boolean",default_value:false},{name:"dynamic_node_properties",type:"symbolic_map"},{name:"distribution_mode",type:"symbol"},{name:"filter",type:"symbolic_map"},{name:"default_outcome",type:"*"},{name:"outcomes",type:"symbol",multiple:true},{name:"capabilities",type:"symbol",multiple:true}]});define_terminus({name:"target",code:41,fields:[{name:"address",type:"string"},{name:"durable",type:"uint",default_value:0},{name:"expiry_policy",type:"symbol",default_value:"session-end"},{name:"timeout",type:"uint",default_value:0},{name:"dynamic",type:"boolean",default_value:false},{name:"dynamic_node_properties",type:"symbolic_map"},{name:"capabilities",type:"symbol",multiple:true}]});module.exports=terminus},{"./types.js":12}],11:[functi
 on(require,module,exports){(function(Buffer){"use strict";var 
frames=require("./frames.js");var log=require("./log.js");var 
Transport=function(identifier,protocol_id,frame_type,handler){this.identifier=identifier;this.protocol_id=protocol_id;this.frame_type=frame_type;this.handler=handler;this.pending=[];this.header_sent=undefined;this.header_received=undefined;this.write_complete=false;this.read_complete=false};Transport.prototype.has_writes_pending=function(){return
 this.pending.length>0};Transport.prototype.encode=function(frame){var 
buffer=frames.write_frame(frame);log.frames("["+this.identifier+"] PENDING: 
"+JSON.stringify(frame));this.pending.push(buffer)};Transport.prototype.write=function(socket){if(!this.header_sent){var
 buffer=new Buffer(8);var 
header={protocol_id:this.protocol_id,major:1,minor:0,revision:0};frames.write_header(buffer,header);socket.write(buffer);this.header_sent=header}for(var
 i=0;i<this.pending.length;i++){socket.write(this.pending[i]);log.raw("["+this.i
 dentifier+"] SENT: 
"+JSON.stringify(this.pending[i]))}this.pending=[]};Transport.prototype.read=function(buffer){var
 offset=0;if(!this.header_received){if(buffer.length<8){return 
offset}else{this.header_received=frames.read_header(buffer);log.frames("["+this.identifier+"]
 RECV: 
"+JSON.stringify(this.header_received));if(this.header_received.protocol_id!==this.protocol_id){throw
 Error("Invalid AMQP protocol id "+this.header_received.protocol_id+" 
expecting: 
"+this.protocol_id)}offset=8}}while(offset<buffer.length&&!this.read_complete){var
 frame_size=buffer.readUInt32BE(offset);log.io("["+this.identifier+"] got frame 
of size 
"+frame_size);if(buffer.length<offset+frame_size){log.io("["+this.identifier+"] 
incomplete frame; have only "+(buffer.length-offset)+" of 
"+frame_size);break}else{var 
frame=frames.read_frame(buffer.slice(offset,offset+frame_size));log.frames("["+this.identifier+"]
 RECV: "+JSON.stringify(frame));if(frame.type!==this.frame_type){throw 
Error("Invalid frame type: "+fr
 
ame.type)}offset+=frame_size;if(frame.performative){frame.performative.dispatch(this.handler,frame)}}}return
 
offset};module.exports=Transport}).call(this,require("buffer").Buffer)},{"./frames.js":3,"./log.js":5,buffer:16}],12:[function(require,module,exports){(function(Buffer){"use
 strict";function 
Typed(type,value){this.type=type;this.value=value}Typed.prototype.toString=function(){return
 
this.value?this.value.toString():null};Typed.prototype.toLocaleString=function(){return
 
this.value?this.value.toLocaleString():null};Typed.prototype.valueOf=function(){return
 this.value};Typed.prototype.toJSON=function(){return 
this.value&&this.value.toJSON?this.value.toJSON():this.value};function 
hex(i){return Number(i).toString(16)}var 
types={by_code:{}};Object.defineProperty(types,"MAX_UINT",{value:4294967295,writable:false,configurable:false});Object.defineProperty(types,"MAX_USHORT",{value:65535,writable:false,configurable:false});function
 define_type(name,typecode,annotations,empty_value){va
 r subcategory=typecode>>>4;var 
t;if(subcategory===4){t=function(){this.type=t;this.value=empty_value}}else 
if(subcategory===14||subcategory===15){t=function(v,code,descriptor){this.type=t;this.value=v;this.array_constructor={typecode:code};if(descriptor){this.array_constructor.descriptor=descriptor}}}else{t=function(v){this.type=t;this.value=v}}t.typecode=typecode;t.prototype=Object.create(Typed.prototype);t.toString=function(){return
 name+"#"+hex(typecode)};switch(subcategory){case 
4:t.width=0;t.category="fixed";break;case 
5:t.width=1;t.category="fixed";break;case 
6:t.width=2;t.category="fixed";break;case 
7:t.width=4;t.category="fixed";break;case 
8:t.width=8;t.category="fixed";break;case 
9:t.width=16;t.category="fixed";break;case 
10:t.width=1;t.category="variable";break;case 
11:t.width=4;t.category="variable";break;case 
12:t.width=1;t.category="compound";break;case 
13:t.width=4;t.category="compound";break;case 
14:t.width=1;t.category="array";break;case 15:t.width=4;t.category="arra
 y";break}if(annotations){for(var a in 
annotations){t[a]=annotations[a]}}types.by_code[t.typecode]=t;types[name]=t;return
 t}function buffer_ops(name){return{read:function(buffer,offset){return 
buffer["read"+name](offset)},write:function(buffer,value,offset){buffer["write"+name](value,offset)}}}function
 buffer_ops_be(name){return{read:function(buffer,offset){return 
buffer["read"+name+"BE"](offset)},write:function(buffer,value,offset){buffer["write"+name+"BE"](value,offset)}}}var
 MAX_UINT=4294967296;var MIN_INT=-2147483647;function 
write_ulong(buffer,value,offset){if(typeof value==="number"||value instanceof 
Number){var hi=Math.floor(value/MAX_UINT);var 
lo=value%MAX_UINT;buffer.writeUInt32BE(hi,offset);buffer.writeUInt32BE(lo,offset+4)}else{value.copy(buffer,offset)}}function
 read_ulong(buffer,offset){var hi=buffer.readUInt32BE(offset);var 
lo=buffer.readUInt32BE(offset+4);if(hi<2097153){return 
hi*MAX_UINT+lo}else{return buffer.slice(offset,offset+8)}}function 
write_long(buffer,value,of
 fset){if(typeof value==="number"||value instanceof Number){var 
abs=Math.abs(value);var hi=Math.floor(abs/MAX_UINT);var 
lo=abs%MAX_UINT;buffer.writeInt32BE(hi,offset);buffer.writeUInt32BE(lo,offset+4);if(value<0){var
 carry=1;for(var i=0;i<8;i++){var index=offset+(7-i);var 
value=(buffer[index]^255)+carry;buffer[index]=value&255;carry=value>>8}}}else{value.copy(buffer,offset)}}function
 read_long(buffer,offset){var hi=buffer.readInt32BE(offset);var 
lo=buffer.readUInt32BE(offset+4);if(hi<2097153&&hi>-2097153){return 
hi*MAX_UINT+lo}else{return 
buffer.slice(offset,offset+8)}}define_type("Null",64,undefined,null);define_type("Boolean",86,buffer_ops("UInt8"));define_type("True",65,undefined,true);define_type("False",66,undefined,false);define_type("Ubyte",80,buffer_ops("UInt8"));define_type("Ushort",96,buffer_ops("UInt16BE"));define_type("Uint",112,buffer_ops("UInt32BE"));define_type("SmallUint",82,buffer_ops("UInt8"));define_type("Uint0",67,undefined,0);define_type("Ulong",128,{write:write_
 
ulong,read:read_ulong});define_type("SmallUlong",83,buffer_ops("UInt8"));define_type("Ulong0",68,undefined,0);define_type("Byte",81,buffer_ops("Int8"));define_type("Short",97,buffer_ops("Int16BE"));define_type("Int",113,buffer_ops("Int32BE"));define_type("SmallInt",84,buffer_ops("Int8"));define_type("Long",129,{write:write_long,read:read_long});define_type("SmallLong",85,buffer_ops("Int8"));define_type("Float",114,buffer_ops_be("Float"));define_type("Double",130,buffer_ops_be("Double"));define_type("Decimal32",116);define_type("Decimal64",132);define_type("Decimal128",148);define_type("CharUTF32",115);define_type("Timestamp",131,{write:write_long,read:read_long});define_type("Uuid",152);define_type("Vbin8",160);define_type("Vbin32",176);define_type("Str8",161,{encoding:"utf8"});define_type("Str32",177,{encoding:"utf8"});define_type("Sym8",163,{encoding:"ascii"});define_type("Sym32",179,{encoding:"ascii"});define_type("List0",69,undefined,[]);define_type("List8",192);define_type("Lis
 
t32",208);define_type("Map8",193);define_type("Map32",209);define_type("Array8",224);define_type("Array32",240);function
 is_one_of(o,typelist){for(var 
i=0;i<typelist.length;i++){if(o.type.typecode===typelist[i].typecode)return 
true}return false}types.is_ulong=function(o){return 
is_one_of(o,[types.Ulong,types.Ulong0,types.SmallUlong])};types.is_string=function(o){return
 is_one_of(o,[types.Str8,types.Str32])};types.is_symbol=function(o){return 
is_one_of(o,[types.Sym8,types.Sym32])};types.is_list=function(o){return 
is_one_of(o,[types.List0,types.List8,types.List32])};types.is_map=function(o){return
 is_one_of(o,[types.Map8,types.Map32])};types.wrap_boolean=function(v){return 
v?new types.True:new types.False};types.wrap_ulong=function(l){if(l===0)return 
new types.Ulong0;else return l>255?new types.Ulong(l):new 
types.SmallUlong(l)};types.wrap_uint=function(l){if(l===0)return new 
types.Uint0;else return l>255?new types.Uint(l):new 
types.SmallUint(l)};types.wrap_ushort=function(l){return ne
 w types.Ushort(l)};types.wrap_ubyte=function(l){return new 
types.Ubyte(l)};types.wrap_long=function(l){return l>127||l<-128?new 
types.Long(l):new types.SmallLong(l)};types.wrap_int=function(l){return 
l>127||l<-128?new types.Int(l):new 
types.SmallInt(l)};types.wrap_short=function(l){return new 
types.Short(l)};types.wrap_byte=function(l){return new 
types.Byte(l)};types.wrap_float=function(l){return new 
types.Float(l)};types.wrap_double=function(l){return new 
types.Double(l)};types.wrap_timestamp=function(l){return new 
types.Timestamp(l)};types.wrap_binary=function(s){return s.length>255?new 
types.Vbin32(s):new types.Vbin8(s)};types.wrap_string=function(s){return 
s.length>255?new types.Str32(s):new 
types.Str8(s)};types.wrap_symbol=function(s){return s.length>255?new 
types.Sym32(s):new 
types.Sym8(s)};types.wrap_list=function(l){if(l.length===0)return new 
types.List0;var items=l.map(types.wrap);return new 
types.List32(items)};types.wrap_map=function(m,key_wrapper){var 
items=[];for(var k 
 in 
m){items.push(key_wrapper?key_wrapper(k):types.wrap(k));items.push(types.wrap(m[k]))}return
 new types.Map32(items)};types.wrap_symbolic_map=function(m){return 
types.wrap_map(m,types.wrap_symbol)};types.wrap_array=function(l,code,descriptors){if(code){return
 new types.Array32(l,code,descriptors)}else{throw Error("An array must specify 
a type for its elements")}};types.wrap=function(o){var t=typeof 
o;if(t==="string"){return types.wrap_string(o)}else if(t=="boolean"){return 
o?new types.True:new types.False}else if(t=="number"||o instanceof 
Number){if(isNaN(o)){throw Error("Cannot wrap NaN! "+o)}else 
if(Math.floor(o)-o!==0){return new types.Double(o)}else 
if(o>0){if(o<MAX_UINT){return types.wrap_uint(o)}else{return 
types.wrap_ulong(o)}}else{if(o>MIN_INT){return types.wrap_int(o)}else{return 
types.wrap_long(o)}}}else if(o instanceof Date){return 
types.wrap_timestamp(o.getTime())}else if(o instanceof Typed){return o}else 
if(t=="undefined"||o===null){return new types.Null}else if(Array.
 isArray(o)){return types.wrap_list(o)}else{return 
types.wrap_map(o)}};types.wrap_described=function(value,descriptor){var 
result=types.wrap(value);if(descriptor){if(typeof 
descriptor==="string"){result=types.described(types.wrap_string(descriptor),result)}else
 if(typeof descriptor==="number"||descriptor instanceof 
Number){result=types.described(types.wrap_ulong(descriptor),result)}}return 
result};types.wrap_message_id=function(o){var t=typeof 
o;if(t==="string"){return types.wrap_string(o)}else if(t=="number"||o 
instanceof Number){return types.wrap_ulong(o)}else{throw Error("invalid message 
id:"+o)}};types.wrap_delivery_state=function(o){return new Null};function 
mapify(elements){var result={};for(var 
i=0;i+1<elements.length;){result[elements[i++]]=elements[i++]}return result}var 
by_descriptor={};types.unwrap=function(o,leave_described){if(o instanceof 
Typed){if(o.descriptor){var c=by_descriptor[o.descriptor.value];if(c){return 
new c(o.value)}else if(leave_described){return o}}var u=
 types.unwrap(o.value,true);return types.is_map(o)?mapify(u):u}else 
if(Array.isArray(o)){return o.map(function(i){return 
types.unwrap(i,true)})}else{return 
o}};types.described=function(descriptor,typedvalue){var 
o=Object.create(typedvalue);if(descriptor.length){o.descriptor=descriptor.shift();return
 described(descriptor,o)}else{o.descriptor=descriptor;return o}};function 
get_type(code){var type=types.by_code[code];if(!type){throw Error("Unrecognised 
typecode: "+hex(code))}return 
type}types.Reader=function(buffer){this.buffer=buffer;this.position=0};types.Reader.prototype.read_typecode=function(){return
 this.read_uint(1)};types.Reader.prototype.read_uint=function(width){var 
current=this.position;this.position+=width;var 
name=width>1?"readUInt"+width*8+"BE":"readUInt"+8;return 
this.buffer[name](current)};types.Reader.prototype.read_fixed_width=function(type){var
 current=this.position;this.position+=type.width;if(type.read){return 
type.read(this.buffer,current)}else{return this.buffer.s
 
lice(current,this.position)}};types.Reader.prototype.read_variable_width=function(type){var
 size=this.read_uint(type.width);var slice=this.read_bytes(size);return 
type.encoding?slice.toString(type.encoding):slice};types.Reader.prototype.read=function(){var
 constructor=this.read_constructor();var 
value=this.read_value(get_type(constructor.typecode));return 
constructor.descriptor?types.described(constructor.descriptor,value):value};types.Reader.prototype.read_constructor=function(){var
 code=this.read_typecode();if(code===0){var d=[];d.push(this.read());var 
c=this.read_constructor();while(c.descriptor){d.push(c.descriptor);c=this.read_constructor()}return{typecode:c.typecode,descriptor:d.length==1?d[0]:d}}else{return{typecode:code}}};types.Reader.prototype.read_value=function(type){if(type.width===0){return
 new type}else if(type.category==="fixed"){return new 
type(this.read_fixed_width(type))}else if(type.category==="variable"){return 
new type(this.read_variable_width(type))}else if(ty
 pe.category==="compound"){return this.read_compound(type)}else 
if(type.category==="array"){return this.read_array(type)}else{throw 
Error("Invalid category for type: 
"+type)}};types.Reader.prototype.read_multiple=function(n,f){var 
read_fn=f?f:this.read.bind(this);var 
items=[];while(items.length<n){items.push(read_fn.apply(this))}return 
items};types.Reader.prototype.read_size_count=function(width){return{size:this.read_uint(width),count:this.read_uint(width)}};types.Reader.prototype.read_compound=function(type){var
 limits=this.read_size_count(type.width);return new 
type(this.read_multiple(limits.count))};types.Reader.prototype.read_array=function(type){var
 limits=this.read_size_count(type.width);var 
constructor=this.read_constructor();var value=new 
type(this.read_multiple(limits.count,this.read_value.bind(this,get_type(constructor.typecode))),constructor.typecode,constructor.descriptor);return
 value};types.Reader.prototype.toString=function(){var 
s="buffer@"+this.position;if(this.posi
 tion)s+=": ";for(var 
i=this.position;i<this.buffer.length;i++){if(i>0)s+=",";s+="0x"+Number(this.buffer[i]).toString(16)}return
 
s};types.Reader.prototype.reset=function(){this.position=0};types.Reader.prototype.skip=function(bytes){this.position+=bytes};types.Reader.prototype.read_bytes=function(bytes){var
 current=this.position;this.position+=bytes;return 
this.buffer.slice(current,this.position)};types.Reader.prototype.remaining=function(){return
 
this.buffer.length-this.position};types.Writer=function(buffer){this.buffer=buffer?buffer:new
 
Buffer(1024);this.position=0};types.Writer.prototype.toBuffer=function(){return 
this.buffer.slice(0,this.position)};function max(a,b){return 
a>b?a:b}types.Writer.prototype.ensure=function(length){if(this.buffer.length<length){var
 bigger=new 
Buffer(max(this.buffer.length*2,length));this.buffer.copy(bigger);this.buffer=bigger}};types.Writer.prototype.write_typecode=function(code){this.write_uint(code,1)};types.Writer.prototype.write_uint=function(val
 ue,width){var 
current=this.position;this.ensure(this.position+width);this.position+=width;var 
name=width>1?"writeUInt"+width*8+"BE":"writeUInt"+8;if(!this.buffer[name]){throw
 Error("Buffer doesn't define "+name)}return 
this.buffer[name](value,current)};types.Writer.prototype.write_fixed_width=function(type,value){var
 
current=this.position;this.ensure(this.position+type.width);this.position+=type.width;if(type.write){type.write(this.buffer,value,current)}else
 if(value.copy){value.copy(this.buffer,current)}else{throw Error("Can't handle 
write for 
"+type)}};types.Writer.prototype.write_variable_width=function(type,value){var 
source=type.encoding?new Buffer(value,type.encoding):new 
Buffer(value);this.write_uint(source.length,type.width);this.write_bytes(source)};types.Writer.prototype.write_bytes=function(source){var
 
current=this.position;this.ensure(this.position+source.length);this.position+=source.length;source.copy(this.buffer,current)};types.Writer.prototype.write_constructor=funct
 
ion(typecode,descriptor){if(descriptor){this.write_typecode(0);this.write(descriptor)}this.write_typecode(typecode)};types.Writer.prototype.write=function(o){if(!(o
 instanceof Typed)){throw Error("Can't write 
"+JSON.stringify(o))}this.write_constructor(o.type.typecode,o.descriptor);this.write_value(o.type,o.value,o.array_constructor)};types.Writer.prototype.write_value=function(type,value,constructor){if(type.width===0){return}else
 if(type.category==="fixed"){this.write_fixed_width(type,value)}else 
if(type.category==="variable"){this.write_variable_width(type,value)}else 
if(type.category==="compound"){this.write_compound(type,value)}else 
if(type.category==="array"){this.write_array(type,value,constructor)}else{throw 
Error("Invalid category "+type.category+" for type: 
"+type)}};types.Writer.prototype.backfill_size=function(width,saved){var 
gap=this.position-saved;this.position=saved;this.write_uint(gap-width,width);this.position+=gap-width};types.Writer.prototype.write_compound=funct
 ion(type,value){var 
saved=this.position;this.position+=type.width;this.write_uint(value.length,type.width);for(var
 
i=0;i<value.length;i++){if(value[i]===undefined||value[i]===null){this.write(new
 
types.Null)}else{this.write(value[i])}}this.backfill_size(type.width,saved)};types.Writer.prototype.write_array=function(type,value,constructor){var
 
saved=this.position;this.position+=type.width;this.write_uint(value.length,type.width);this.write_constructor(constructor.typecode,constructor.descriptor);var
 type=get_type(constructor.typecode);for(var 
i=0;i<value.length;i++){this.write_value(type,value[i])}this.backfill_size(type.width,saved)};types.Writer.prototype.toString=function(){var
 s="buffer@"+this.position;if(this.position)s+=": ";for(var 
i=0;i<this.position;i++){if(i>0)s+=",";s+=("00"+Number(this.buffer[i]).toString(16)).slice(-2)}return
 
s};types.Writer.prototype.skip=function(bytes){this.ensure(this.position+bytes);this.position+=bytes};types.Writer.prototype.clear=function(){this.
 
buffer.fill(0);this.position=0};types.Writer.prototype.remaining=function(){return
 this.buffer.length-this.position};function 
get_constructor(typename){if(typename==="symbol"){return{typecode:types.Sym8.typecode}}throw
 Error("TODO: Array of type "+typename+" not yet supported")}function 
wrap_field(definition,instance){if(instance!==undefined&&instance!==null){if(Array.isArray(instance)){if(!definition.multiple){throw
 Error("Field "+definition.name+" does not support multiple values, got 
"+JSON.stringify(instance))}var 
constructor=get_constructor(definition.type);return 
types.wrap_array(instance,constructor.typecode,constructor.descriptor)}else 
if(definition.type==="*"){return instance}else{var 
wrapper=types["wrap_"+definition.type];if(wrapper){return 
wrapper(instance)}else{throw Error("No wrapper for field "+definition.name+" of 
type "+definition.type)}}}else if(definition.mandatory){throw Error("Field 
"+definition.name+" is mandatory")}else{return new types.Null}}function 
get_acces
 sors(index,field_definition){var getter=function(){return 
field_definition.type==="*"?this.value[index]:types.unwrap(this.value[index])};var
 
setter=function(o){this.value[index]=wrap_field(field_definition,o)};return{get:getter,set:setter,enumerable:true,configurable:false}}types.define_composite=function(def){var
 
c=function(fields){this.value=fields?fields:[]};c.descriptor={numeric:def.code,symbolic:"amqp:"+def.name+":list"};c.prototype.dispatch=function(target,frame){target["on_"+def.name](frame)};for(var
 i=0;i<def.fields.length;i++){var 
f=def.fields[i];Object.defineProperty(c.prototype,f.name,get_accessors(i,f))}c.toString=function(){return
 def.name+"#"+Number(def.code).toString(16)};c.prototype.toJSON=function(){var 
o={};for(var f in this){if(f!=="value"&&this[f]){o[f]=this[f]}}return 
o};c.create=function(fields){var o=new c;for(var f in 
fields){o[f]=fields[f]}return o};c.prototype.described=function(fields){return 
types.described(types.wrap_ulong(c.descriptor.numeric),types.wra
 p_list(this.value))};return c};function add_type(def){var 
c=types.define_composite(def);types["wrap_"+def.name]=function(fields){return 
c.create(fields).described()};by_descriptor[Number(c.descriptor.numeric).toString(10)]=c;by_descriptor[c.descriptor.symbolic]=c}add_type({name:"error",code:29,fields:[{name:"condition",type:"symbol",mandatory:true},{name:"description",type:"string"},{name:"info",type:"map"}]});module.exports=types}).call(this,require("buffer").Buffer)},{buffer:16}],13:[function(require,module,exports){"use
 strict";var util={};util.generate_uuid=function(){var 
uuid="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var 
r=Math.random()*16|0,v=c=="x"?r:r&3|8;return v.toString(16)});return 
uuid};util.clone=function(o){var copy=Object.create(o.prototype||{});var 
names=Object.getOwnPropertyNames(o);for(var i=0;i<names.length;i++){var 
key=names[i];copy[key]=o[key]}return 
copy};module.exports=util},{}],14:[function(require,module,exports){(function(Buffer){"
 use strict";function nulltransform(data){return data}function 
from_arraybuffer(data){if(data instanceof ArrayBuffer)return new Buffer(new 
Uint8Array(data));else return new Buffer(data)}function 
to_typedarray(data){return new Uint8Array(data)}function wrap(ws){var 
data_recv=nulltransform;var 
data_send=nulltransform;if(ws.binaryType){ws.binaryType="arraybuffer";data_recv=from_arraybuffer;data_send=to_typedarray}return{end:function(){ws.close()},write:function(data){try{ws.send(data_send(data),{binary:true})}catch(e){ws.onerror(e)}},on:function(event,handler){if(event==="data"){ws.onmessage=function(msg_evt){handler(data_recv(msg_evt.data))}}else
 if(event==="end"){ws.onclose=handler}else 
if(event==="error"){ws.onerror=handler}else{console.log("ERROR: Attempt to set 
unrecognised handler on websocket wrapper: 
"+event)}},get_id_string:function(){return 
ws.url}}}module.exports={connect:function(Impl){return 
function(url,protocols,options){return 
function(){return{connect:function(port_igno
 re,host_ignore,options_ignore,callback){var c=new Impl(url,protocols,o

<TRUNCATED>

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to