constructor(c_mesh, c_link, open){ super({objectMode : true}); let buf = lob.encode(open.json, new Buffer(open.body || 0)); let c_lob = lob_to_c(buf); this._c_mesh = c_mesh; this._c_chan = link_chan(c_link, c_lob); this._open = c_lob; chan_handle(this._c_chan, () => { let c_lob; while(c_lob = chan_receiving(this._c_chan)) { let lob = lob_from_c(c_lob); //console.log("LOB", lob) if (lob) this.push(lob); else console.log("bad lob",buf_lob_from_c(c_lob).toString()) } }, null); this.on('data',(packet) => { this.receiving(null, packet, () => {}); }) }
this.writeHead = function THTP_writeHead(statusCode, reasonPhrase, headers) { // don't double! this._header = "" if(head){ //console.log('double call to thtp writeHead',this.statusCode,(new Error()).stack) return this; }; head = true; // be friendly if(!headers && typeof reasonPhrase == 'object'){ headers = reasonPhrase; reasonPhrase = false; } else if (!headers ){ headers = this._headers; } this.statusCode = parseInt(statusCode) || 500; var json = {}; json[':status'] = this.statusCode; if(reasonPhrase) json[':reason'] = reasonPhrase; if(headers) Object.keys(headers).forEach(function ForEachHeader(header){ json[header.toLowerCase()] = headers[header]; }); stream.write(lob.encode(json,false)); return this; };
x.handshake = function(){ var inner = hashname.toPacket(self.keys,csid); delete inner.json[csid]; // is implied here inner.json.at = x._at; self.debug('handshake generated',x._at); return x.encrypt(lob.encode(inner)); };
direct(open, body){ let buf = lob.encode(open, new Buffer(body)); link_direct( this._c_link, lob_to_c(buf) ); }
_write(packet, enc, cb){ packet.json.c = chan_id(this._c_chan); this.c_send(lob_to_c(lob.encode(packet.json, packet.body))); cb(); }
pipe.onSend = function(packet, link, cbSend) { if (!ws) return; // Disconnected var buf = lob.encode(packet); ws.send(buf.toString('binary'), cbSend); };
pipe.onSend = function(packet, link, cbSend) { if (!ws) return; // Disconnected var buf = lob.encode(packet); sendmsg(buf, cbSend); };