Ejemplo n.º 1
0
int getFile(int sock, char *p_ad, char* p_hid, const char *fin, const char *fout)
{
	int chunkSock;
	int offset;
	char cmd[512];
	char reply[512];
	int status = 0;
	
	//TODO: check the arguments to be correct
	
	// send the file request
	sprintf(cmd, "get %s",  fin);
	sendCmd(sock, cmd);

	// get back number of chunks in the file
	if (getChunkCount(sock, reply, sizeof(reply)) < 1){
		warn("could not get chunk count. Aborting. \n");
		return -1;
	}

	int count = atoi(&reply[4]);

	if ((chunkSock = Xsocket(AF_XIA, XSOCK_CHUNK, 0)) < 0)
		die(-1, "unable to create chunk socket\n");

	FILE *f = fopen(fout, "w");

	offset = 0;
	while (offset < count) {
		int num = NUM_CHUNKS;
		if (count - offset < num)
			num = count - offset;

		// tell the server we want a list of <num> cids starting at location <offset>
		sprintf(cmd, "block %d:%d", offset, num);
		sendCmd(sock, cmd);

		if (getChunkCount(sock, reply, sizeof(reply)) < 1){
			warn("could not get chunk count. Aborting. \n");
			return -1;
		}
		offset += NUM_CHUNKS;
		if (getListedChunks(chunkSock, f, &reply[4], p_ad, p_hid) < 0) {
			status= -1;
			break;
		}
	}
	
	fclose(f);

	if (status < 0) {
		unlink(fin);
	}

	say("Received file %s\n", fout);
	sendCmd(sock, "done");
	Xclose(chunkSock);
	return status;
}
Ejemplo n.º 2
0
*/
void TransferRequest::print( ATP_TransferRequest_t * frame ){
	Log.Debug("TransferRequest object:"CR);

	if ( getFrameType(frame) == ATP_TRANSFER_REQUEST ) Log.Debug("type:        ATP_TRANSFER_REQUEST"CR );
	if ( getFrameType(frame) == ATP_CHUNK_REQUEST ) Log.Debug(   "type:        ATP_CHUNK_REQUEST"CR );
	if ( getFrameType(frame) == ATP_CHUNK_RESPONSE ) Log.Debug("type:        ATP_CHUNK_RESPONSE"CR );

	Log.Debug("frameID:       %s"CR, getFrameID(frame));
	Log.Debug("frameType:     %d"CR, getFrameType(frame));	
	Log.Debug("meshAddress:   %l"CR, getMeshAddress(frame));	
	Log.Debug("datetime:      %l"CR, getDatetime(frame));	
	Log.Debug("atpID:         %l"CR, getAtpID(frame)); 	
	Log.Debug("version:       %d"CR, getVersion(frame));
	Log.Debug("topchunk:      %d"CR, getTopChunk(frame));
	Log.Debug("chunkcount:    %d"CR, getChunkCount(frame));

	if ( getStatus(frame) == ATP_IDLE ) Log.Debug(                 "status:        ATP_IDLE"CR );
	if ( getStatus(frame) == ATP_SUCCESS ) Log.Debug(              "status:        ATP_SUCCESS"CR );
	if ( getStatus(frame) == ATP_FAILED_DURING_TRANSIT ) Log.Debug("status:        ATP_FAILED_DURING_TRANSIT"CR );
	if ( getStatus(frame) == ATP_FAILED_CHECKSUM ) Log.Debug(   "status:        ATP_FAILED_CHECKSUM"CR );
	if ( getStatus(frame) == ATP_FAILED_ENCRYPTION ) Log.Debug( "status:        ATP_FAILED_ENCRYPTION"CR );
	if ( getStatus(frame) == ATP_FAILED_COMPRESSION ) Log.Debug("status:        ATP_FAILED_COMPRESSION"CR );
	if ( getStatus(frame) == ATP_UNSENT ) Log.Debug(            "status:        ATP_UNSENT"CR );
	if ( getStatus(frame) == ATP_SENT ) Log.Debug(              "status:        ATP_SENT"CR );
	if ( getStatus(frame) == ATP_RECEIVED ) Log.Debug(          "status:        ATP_RECEIVED"CR );
	if ( getStatus(frame) == ATP_WORKING ) Log.Debug(          "status:        ATP_WORKING"CR );
	
	Log.Debug("size:          %l"CR, getSize(frame));
	Log.Debug("expires:       %l"CR, getExpires(frame));	
	Log.Debug("descriptor:    %s"CR, getDescriptor(frame));	
	Log.Debug("source:        %l"CR, getSource(frame));	
	Log.Debug("destination:   %l"CR, getDestination(frame));	
	Log.Debug("fileName:      %s"CR, getFileName(frame));
	
	if ( getBuffer(frame) != 0 ){
		Log.Debug("buffer:      %s"CR, getBuffer(frame));
	}