@Override public void onRecv(byte[] b, int off, int len) { if (peer != null) { peer.handler.send(b, off, len); } }
@Override public void onRecv(byte[] b, int off, int len) { if (b[len - 1] == 0) { loadPolicy(); handler.send(policyBytes); handler.disconnect(); } } };
/** Wraps buffer size events, from the application side to the network side */ @Override public void setBufferSize(int bufferSize) { handler.setBufferSize(bufferSize); }
TerminalConnection connection = connectionMap.get(Integer.valueOf(cid)); if (connection != null && packet.size > 0) { connection.handler.send(b, off, packet.size); } else if (logLevel >= LOG_DEBUG) { Log.d("HANDLER_SEND: " + (connection == null ? connection = connectionMap.get(Integer.valueOf(cid)); if (connection != null) { connection.handler.send(b, dataOff, dataLen); } else if (logLevel >= LOG_DEBUG) { Log.d("HANDLER_MULTICAST: Not Found, #" + cid + recv); if (connection != null && packet.size >= 2) { int bufferSize = Bytes.toShort(b, off) & 0xFFFF; connection.handler.setBufferSize(bufferSize); if (logLevel >= LOG_VERBOSE) { Log.v("HANDLER_BUFFER: " + bufferSize + idPool.returnId(cid); connection.activeClose = true; connection.handler.disconnect(); if (logLevel >= LOG_VERBOSE) { Log.v("HANDLER_DISCONNECT: #" + cid + connection.send + recv);
/** Wraps active disconnecting events, from the application side to the network side */ @Override public void disconnect() { handler.disconnect(); } }
@Override public void onDisconnect() { if (peer != null) { peer.peer = null; peer.handler.disconnect(); } } }
/** Wraps sent data, from the application side to the network side */ @Override public void send(byte[] b, int off, int len) { handler.send(b, off, len); }
void disconnect() { activeClose = true; handler.disconnect(); onDisconnect(); } }
@Override public void onQueue(int size) { if (peer != null) { peer.handler.setBufferSize(size == 0 ? MAX_BUFFER_SIZE : 0); } }
/** Sends a sequence of bytes in the application end. */ public void send(byte[] b, int off, int len); /**
void disconnect() { activeClose = true; handler.disconnect(); onDisconnect(); } }
@Override public void onQueue(int size) { if (logLevel >= LOG_VERBOSE) { Log.v("onQueue(" + size + ")" + send); } if (!context.isQueueStatusChanged(size, lastSize)) { return; } int bufferSize = size == 0 ? 0 : Connection.MAX_BUFFER_SIZE; // block or unblock all "TerminateConnection"s when mux is congested or smooth for (TerminalConnection connection : connectionMap. values().toArray(EMPTY_CONNECTIONS)) { // "setBuferSize" might change "connectionMap" connection.handler.setBufferSize(bufferSize); } if (logLevel >= LOG_DEBUG) { Log.d((size == 0 ? "All Terminal Connections Unblocked due to Smooth Mux" : "All Terminal Connections Blocked due to Congested Mux (" + size + ")") + send); } }
@Override public void onRecv(byte[] b, int off, int len) { for (ConnectionHandler handler_ : handlers.toArray(EMPTY_HANDLERS)) { // "connection.onDisconnect()" might change "handlers" if (!noEcho || handler_ != handler) { handler_.send(b, off, len); } } }
public OriginServer(ServerConnection server, MuxContext context) { this.server = server; this.context = context; closeable = context.scheduleDelayed(() -> { long now = System.currentTimeMillis(); Iterator<OriginMuxConnection> i = timeoutSet.iterator(); OriginMuxConnection mux; while (i.hasNext() && now > (mux = i.next()).accessed + 60000) { i.remove(); mux.handler.disconnect(); } }, 1000, 1000); }
static void send(ConnectionHandler handler, byte[] b, int cmd, int cid) { Bytes.setShort(HEAD_TAG, b, 0); Bytes.setShort(b.length - HEAD_SIZE, b, 2); Bytes.setShort(cmd, b, 4); Bytes.setShort(cid, b, 6); handler.send(b); } }
@Override public void onDisconnect() { for (TerminalConnection connection : connectionMap. values().toArray(EMPTY_CONNECTIONS)) { // "conn.onDisconnect()" might change "connectionMap" connection.activeClose = true; connection.handler.disconnect(); } if (logLevel >= LOG_DEBUG) { Log.d(!established ? "Mux Connection Failed" : activeClose ? "Mux Connection Disconnected" + send : "Mux Connection Lost" + recv); } }
static void send(ConnectionHandler handler, int cmd, int cid) { byte[] head = new byte[8]; Bytes.setShort(HEAD_TAG, head, 0); Bytes.setShort(0, head, 2); Bytes.setShort(cmd, head, 4); Bytes.setShort(cid, head, 6); handler.send(head); }
@Override public void onConnect(ConnectionSession session) { peer = new PeerConnection(this); Connection connection = peer; for (Supplier<? extends ConnectionFilter> serverFilter : forward.serverFilters) { connection = connection.appendFilter(serverFilter.get()); } try { forward.connector.connect(connection, forward.host, forward.port); } catch (IOException e) { peer = null; handler.disconnect(); } } }
/** * @param handler {@link ConnectionHandler} to write into * @param begin <code>true</code> to write entire Request or Response, * including Start Line and Headers, * and <code>false</code> to write Body and Trailers (if available) only * @param forceChunked <code>true</code> to force to write in Chunked mode */ public void write(ConnectionHandler handler, boolean begin, boolean forceChunked) { ByteArrayQueue data = new ByteArrayQueue(); write(data, begin, forceChunked); handler.send(data.array(), data.offset(), data.length()); } }
cid = mux.idPool.borrowId(); if (cid < 0) { handler.disconnect(); if (logLevel >= LOG_DEBUG) { Log.d("Unable to Allocate Connection ID !!!");