public static ClientSocketWriterStage newInstance(GraphManager graphManager, ClientCoordinator ccm, Pipe<NetPayloadSchema>[] input) { return new ClientSocketWriterStage(graphManager, ccm, input); }
@Override public void run() { boolean doingWork; boolean didWork = false; doingWork = false; int i = input.length; while (--i >= 0) { if (connections[i]==null) { Pipe<NetPayloadSchema> pipe = input[i]; while (connections[i]==null && Pipe.hasContentToRead(pipe)) { doingWork |= writeAll(doingWork, i, pipe, Pipe.peekInt(pipe)); } } else { //we have multiple connections so one blocking does not impact others. doingWork |= tryWrite(i); } } didWork |= doingWork; // //we have no pipes to monitor so this must be done explicitly if (didWork && (null != this.didWorkMonitor)) { this.didWorkMonitor.published(); } }
private boolean writeAll(boolean didWork, int i, Pipe<NetPayloadSchema> pipe, int msgIdx) { //For the close test we must be sending a plain then a disconnect NOT two plains!! //Any sequential Plain or Encrypted values will be rolled together at times on the same connection. if (NetPayloadSchema.MSG_PLAIN_210 == msgIdx) { didWork = writePlain(didWork, i, pipe); } else { didWork = writeAllLessCommon(didWork, i, pipe, msgIdx); } return didWork; }
private boolean writeAllLessCommon(boolean didWork, int i, Pipe<NetPayloadSchema> pipe, int msgIdx) { if (NetPayloadSchema.MSG_ENCRYPTED_200 == msgIdx) { didWork = writeEncrypted(didWork, i, pipe); } else if (NetPayloadSchema.MSG_UPGRADE_307 == msgIdx) { throw new UnsupportedOperationException("Connection upgrade is not yet supported."); } else if (NetPayloadSchema.MSG_BEGIN_208 == msgIdx) { writeBegin(pipe); } else if (NetPayloadSchema.MSG_DISCONNECT_203 == msgIdx) { didWork = writeDisconnect(pipe); } else { didWork = writeShutdown(didWork, pipe); } return didWork; }
cc = checkBuffers(i, pipe, cc); connections[i] = cc; didWork |= tryWrite(i); return didWork;
ClientSocketWriterStage.newInstance(gm, clientCoordinator, input); new SocketTestGenStage(gm, input, testUsers, testSeeds, testSizes, clientCoordinator, port);
private boolean writeShutdown(boolean didWork, Pipe<NetPayloadSchema> pipe) { int msgIdx = Pipe.takeMsgIdx(pipe); if (msgIdx==-1) { Pipe.confirmLowLevelRead(pipe, Pipe.EOF_SIZE); } else { logger.info("unknown message idx received: {}",msgIdx); } Pipe.releaseReadLock(pipe); assert(-1 == msgIdx) : "Expected end of stream shutdown got "+msgIdx; if (--this.shutCountDown <= 0) { requestShutdown(); didWork = false; //set to false so we exit. } return didWork; }
private boolean writeEncrypted(boolean didWork, int i, Pipe<NetPayloadSchema> pipe) { long chnl = Pipe.peekLong(pipe, 0xF&NetPayloadSchema.MSG_ENCRYPTED_200_FIELD_CONNECTIONID_201); ClientConnection cc = (ClientConnection)ccm.lookupConnectionById(chnl); if (null==cc) {//closed or we can not get it yet, just push back till later. return false; } final int msgIdx = Pipe.takeMsgIdx(pipe); final long channelId = Pipe.takeLong(pipe); assert(chnl==channelId); final long arrivalTime = Pipe.takeLong(pipe); int meta = Pipe.takeByteArrayMetaData(pipe); //for string and byte array int len = Pipe.takeByteArrayLength(pipe); if (showWrites) { logger.info("/////\n/// has connection "+((cc!=null)&&cc.isValid())+" channelId "+channelId+" write encrypted length:"+len); } didWork = wrapupUpEncryptedToSingleWrite(didWork, i, pipe, msgIdx, channelId, meta, len, cc); return didWork; }
didWork = rollUpPlainsToSingleWrite(didWork, i, pipe, msgIdx, channelId, cc, meta, len);
checkBuffers(i, pipe, cc); didWork |= tryWrite(i); return didWork;
ClientSocketWriterStage.newInstance(gm, clientCoordinator, input); new SocketTestGenStage(gm, input, testUsers, testSeeds, testSizes, clientCoordinator, port);
public static void buildSimpleTLSClient(GraphManager graphManager, ClientCoordinator clientCoordinator, Pipe<NetPayloadSchema>[] clientPlainOutput, Pipe<NetPayloadSchema>[] clientPlainInput) { Pipe<ReleaseSchema>[] clientReleaseAck =new Pipe[] {ReleaseSchema.instance.newPipe(1024, 0)}; Pipe<NetPayloadSchema>[] clientHandshakePipe = new Pipe[] {NetPayloadSchema.instance.newPipe(8, 1<<16)}; Pipe<NetPayloadSchema>[] clientEncyptedInput = Pipe.buildPipes(clientPlainInput); Pipe<NetPayloadSchema>[] clientEncryptedOutput = Pipe.buildPipes(clientPlainOutput); ClientSocketReaderStage reader = new ClientSocketReaderStage(graphManager, clientCoordinator, clientReleaseAck, clientEncyptedInput ); GraphManager.addNota(graphManager, GraphManager.DOT_RANK_NAME, "SocketReader", reader); SSLEngineUnWrapStage unwrap = new SSLEngineUnWrapStage(graphManager, clientCoordinator, clientEncyptedInput, clientPlainInput, clientReleaseAck[0], clientHandshakePipe[0], false /*isServer*/); GraphManager.addNota(graphManager, GraphManager.DOT_RANK_NAME, "UnWrap", unwrap); new SSLEngineWrapStage(graphManager, clientCoordinator, false /*isServer*/, clientPlainOutput, clientEncryptedOutput); new ClientSocketWriterStage(graphManager, clientCoordinator, PronghornStage.join(clientEncryptedOutput, clientHandshakePipe)); }
ClientSocketWriterStage socketWriteStage = new ClientSocketWriterStage(gm, ccm, clientRequests[i]); GraphManager.addNota(gm, GraphManager.DOT_RANK_NAME, "SocketWriter", socketWriteStage); ccm.processNota(gm, socketWriteStage);