示例#1
0
void masterconn_sendregister(masterconn *eptr) {
	uint8_t *buff;
	uint32_t myip;
	uint16_t myport;
	uint64_t usedspace,totalspace;
	uint64_t tdusedspace,tdtotalspace;
	uint32_t chunkcount,tdchunkcount;


	myip = csserv_getlistenip();
	myport = csserv_getlistenport();
	if (eptr->new_register_mode) {
#ifdef MFSDEBUG
		syslog(LOG_NOTICE,"register ver. 6 - init + space info");
#endif
		hdd_get_space(&usedspace,&totalspace,&chunkcount,&tdusedspace,&tdtotalspace,&tdchunkcount);
		if (eptr->gotrndblob && AuthCode) {
			md5ctx md5c;
			buff = masterconn_create_attached_packet(eptr,CSTOMA_REGISTER,1+16+4+4+2+2+2+8+8+4+8+8+4);
			put8bit(&buff,60);
			md5_init(&md5c);
			md5_update(&md5c,eptr->rndblob,16);
			md5_update(&md5c,(const uint8_t *)AuthCode,strlen(AuthCode));
			md5_update(&md5c,eptr->rndblob+16,16);
			md5_final(buff,&md5c);
			buff+=16;
		} else {
			buff = masterconn_create_attached_packet(eptr,CSTOMA_REGISTER,1+4+4+2+2+2+8+8+4+8+8+4);
			put8bit(&buff,60);
		}
		put32bit(&buff,VERSHEX);
		put32bit(&buff,myip);
		put16bit(&buff,myport);
		put16bit(&buff,Timeout);
		put16bit(&buff,masterconn_getcsid());
		put64bit(&buff,usedspace);
		put64bit(&buff,totalspace);
		put32bit(&buff,chunkcount);
		put64bit(&buff,tdusedspace);
		put64bit(&buff,tdtotalspace);
		put32bit(&buff,tdchunkcount);
	} else {
#ifdef MFSDEBUG
		syslog(LOG_NOTICE,"register ver. 5 - init");
#endif
		buff = masterconn_create_attached_packet(eptr,CSTOMA_REGISTER,1+4+4+2+2);
		put8bit(&buff,50);
		put32bit(&buff,VERSHEX);
		put32bit(&buff,myip);
		put16bit(&buff,myport);
		if (Timeout>0) {
			put16bit(&buff,Timeout);
		} else {
			put16bit(&buff,10);
		}
	}
}
示例#2
0
//封装向Master发送注册信息的packet,存入服务队列
//调用:masterconn_connected()
void masterconn_sendregister(masterconn *eptr) {
	uint8_t *buff;
	uint32_t chunks,myip;
	uint16_t myport;
	uint64_t usedspace,totalspace;
	uint64_t tdusedspace,tdtotalspace;
	uint32_t chunkcount,tdchunkcount;

	myip = csserv_getlistenip();
	myport =  csserv_getlistenport();
	hdd_get_space(&usedspace,&totalspace,&chunkcount,&tdusedspace,&tdtotalspace,&tdchunkcount);
	chunks = hdd_get_chunks_count();
	buff = masterconn_create_attached_packet(eptr,CSTOMA_REGISTER,1+4+4+2+2+8+8+4+8+8+4+chunks*(8+4));
	if (buff==NULL) {
		eptr->mode=KILL;
		hdd_get_chunks_data(NULL);	// unlock
		return;
	}
	put8bit(&buff,4);
	/* put32bit(&buff,VERSION): */
	put16bit(&buff,VERSMAJ);
	put8bit(&buff,VERSMID);
	put8bit(&buff,VERSMIN);
	put32bit(&buff,myip);
	put16bit(&buff,myport);
	put16bit(&buff,Timeout);
	put64bit(&buff,usedspace);
	put64bit(&buff,totalspace);
	put32bit(&buff,chunkcount);
	put64bit(&buff,tdusedspace);
	put64bit(&buff,tdtotalspace);
	put32bit(&buff,tdchunkcount);
	if (chunks>0) {
		hdd_get_chunks_data(buff);
	} else {
		hdd_get_chunks_data(NULL);	// unlock
	}
}