void addSessionToSessionList(char *eth_src,char *eth_dst,char *ip_src,char *ip_dst,unsigned int port,unsigned char *payload,int payloadSize) { SESSION_INFO si; std::list<SESSION_INFO>::iterator tIt; if(SESSION_DEBUG) printf("addSessionToSessionList\n"); int currentSessionSize=SESSION_LIST.size(); unsigned char *npayload; //allocate memory for new payload buffer //npayload=new unsigned char[payloadSize+1]; npayload=(unsigned char*)malloc(payloadSize+1); memcpy(npayload,payload,payloadSize); //filter if(!preCheck(payload)) { pthread_mutex_unlock(&tMutex); return; } //added (bug fix i would imagine) if(SESSION_DEBUG) printf("creating new session for payload!\n"); strcpy(si.ether_src,eth_src); strcpy(si.ether_dst,eth_dst); strcpy(si.ip_src,ip_src); strcpy(si.ip_dst,ip_dst); si.port=port; si.cStarted=si.cEnded=si.cFound=si.lWritten=false; //added if(checkPayload(payload,si,payloadSize)) si.pData.push_back(npayload); else delete npayload; SESSION_LIST.push_back(si); if(SESSION_DEBUG) printf("adding new session to session slot: %i\n",currentSessionSize+1); }
void addPayloadToSession(std::list<SESSION_INFO>::iterator Session,unsigned char *payload,int payloadSize) { unsigned char *npayload; //add if(SESSION_DEBUG) printf("addPayloadToSession\n"); //allocate memory for new payload buffer //npayload=new unsigned char[payloadSize+1]; npayload=(unsigned char*)malloc(payloadSize+1); memcpy(npayload,payload,payloadSize); //filter if(checkPayload(payload,Session,payloadSize)) { if(SESSION_DEBUG) printf("session exists, adding payload!\n"); Session->pData.push_back(npayload); } else delete npayload; //pthread_mutex_unlock(&tMutex); }
/** The client side function that 'does everything' @param request_type The type of request to be run. @param response_type The expected response type. Returns 1 if this remote state is returned, 0 otherwise. (TODO: Double check this documentation.) @param xid The (stateMachine) transaction id. Set to a random number when calling BEGIN. To prevent deadlock, it's best to choose a number unlikely to correspond to an active transaction. (A random number within 2^32 of the highest 64-bit integer will work.) @param reply_type When should the local call return? The choices are AWAIT_ARRIVAL, which returns after hearing back from the coordinator, AWAIT_COMMIT_POINT to wait until after the transaction commits/aborts, AWAIT_RESULT, which waits for the actual result from one of the replicas. @param key, key_size, value, value_size depend on the value of request_type. @return 1 on success, 0 on failure. */ static int _chtEval(DfaSet * dfaSet, unsigned char request_type, unsigned char response_type, state_machine_id * xid, clusterHashTable_t * ht, void * key, size_t * key_size, void * value, size_t * value_size) { /* Fill out a message payload. */ Message m; if(ht != NULL) { DEBUG("_chtEval(request=%d, response=%d, xid=%ld, ht=%d ", request_type, response_type, *xid, ht->id); } else { DEBUG("_chtEval(request=%d, response=%d, xid=%ld, ht=NULL ", request_type, response_type, *xid); } if(key == NULL) { DEBUG(")\n"); } else { DEBUG("key=%d)\n", *(int*)key); } * requestType(&m) = request_type; m.response_type = response_type; setKeyLength(&m, *key_size); setValLength(&m, *value_size); assert(checkPayload(&m)); if(key_size != 0) { memcpy(getKeyAddr(&m), key, *key_size); } if(value_size != 0) { memcpy(getValAddr(&m), value, *value_size); } if(ht != NULL) { memcpy(&(__header_ptr(&m)->hashTable), ht, sizeof(clusterHashTable_t)); } else { //memset(&(__header_ptr(&m)->hashTable), 0, sizeof(clusterHashTable_t)); } /* printf("%s <- %s\n", __header_ptr(&m)->initiator, dfaSet->networkSetup.localhost); */ /* Synchronously run the request */ request(dfaSet, response_type, "bc:0", *xid, &m); if(!checkPayload(&m)) { printf("_chtEval failed: Invalid response.\n"); assert(0); } /* Copy message contents back into caller's buffers, even if the request failed. (There may be app-specific information in the response...) */ if(ht != NULL) { memcpy(ht, &(__header_ptr(&m)->hashTable), sizeof(clusterHashTable_t)); } if (*key_size != 0) { /* printf("\n+%x<-%x+, length %d value=%s and %s\n", (unsigned int) value, (unsigned int)getValAddr(&m), getValLength(&m), value, getValAddr(&m)); */ memcpy(value, getValAddr(&m), getValLength(&m)); } if (*value_size != 0) { memcpy(key, getKeyAddr(&m), getKeyLength(&m)); } *value_size = getValLength(&m); *key_size = getKeyLength(&m); *xid = m.to_machine_id; DEBUG("+chtEval returning %d\n", m.type); // return m.type; return 1; }