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); } } }
void masterconn_check_hdd_reports() { masterconn *eptr = masterconnsingleton; uint32_t errorcounter; uint32_t chunkcounter; uint8_t *buff; if (eptr->mode==DATA || eptr->mode==HEADER) { if (hdd_spacechanged()) { uint64_t usedspace,totalspace,tdusedspace,tdtotalspace; uint32_t chunkcount,tdchunkcount; buff = masterconn_create_attached_packet(eptr,CSTOMA_SPACE,8+8+4+8+8+4); if (buff) { hdd_get_space(&usedspace,&totalspace,&chunkcount,&tdusedspace,&tdtotalspace,&tdchunkcount); put64bit(&buff,usedspace); put64bit(&buff,totalspace); put32bit(&buff,chunkcount); put64bit(&buff,tdusedspace); put64bit(&buff,tdtotalspace); put32bit(&buff,tdchunkcount); } } errorcounter = hdd_errorcounter(); while (errorcounter) { masterconn_create_attached_packet(eptr,CSTOMA_ERROR_OCCURRED,0); errorcounter--; } chunkcounter = hdd_get_damaged_chunk_count(); // lock if (chunkcounter) { buff = masterconn_create_attached_packet(eptr,CSTOMA_CHUNK_DAMAGED,8*chunkcounter); if (buff) { hdd_get_damaged_chunk_data(buff); // unlock } else { hdd_get_damaged_chunk_data(NULL); // unlock } } else { hdd_get_damaged_chunk_data(NULL); } chunkcounter = hdd_get_lost_chunk_count(); // lock if (chunkcounter) { buff = masterconn_create_attached_packet(eptr,CSTOMA_CHUNK_LOST,8*chunkcounter); if (buff) { hdd_get_lost_chunk_data(buff); // unlock } else { hdd_get_lost_chunk_data(NULL); // unlock } } else { hdd_get_lost_chunk_data(NULL); } } }
void masterconn_check_hdd_space() { masterconn *eptr = masterconnsingleton; uint8_t *buff; if ((eptr->registerstate==REGISTERED || eptr->registerstate==INPROGRESS) && eptr->mode==DATA) { if (hdd_spacechanged()) { uint64_t usedspace,totalspace,tdusedspace,tdtotalspace; uint32_t chunkcount,tdchunkcount; buff = masterconn_create_attached_packet(eptr,CSTOMA_SPACE,8+8+4+8+8+4); hdd_get_space(&usedspace,&totalspace,&chunkcount,&tdusedspace,&tdtotalspace,&tdchunkcount); put64bit(&buff,usedspace); put64bit(&buff,totalspace); put32bit(&buff,chunkcount); put64bit(&buff,tdusedspace); put64bit(&buff,tdtotalspace); put32bit(&buff,tdchunkcount); } } }
void masterconn_sendchunksinfo(masterconn *eptr) { uint8_t *buff; uint32_t chunks; uint64_t usedspace,totalspace; uint64_t tdusedspace,tdtotalspace; uint32_t chunkcount,tdchunkcount; #ifdef MFSDEBUG syslog(LOG_NOTICE,"register ver. %u - chunks info",(eptr->new_register_mode)?6:5); #endif hdd_get_chunks_begin(0); while ((chunks = hdd_get_chunks_next_list_count())) { buff = masterconn_create_attached_packet(eptr,CSTOMA_REGISTER,1+chunks*(8+4)); if (eptr->new_register_mode) { put8bit(&buff,61); } else { put8bit(&buff,51); } hdd_get_chunks_next_list_data(buff); } hdd_get_chunks_end(); if (eptr->new_register_mode) { #ifdef MFSDEBUG syslog(LOG_NOTICE,"register ver. 6 - end"); #endif buff = masterconn_create_attached_packet(eptr,CSTOMA_REGISTER,1); put8bit(&buff,62); } else { #ifdef MFSDEBUG syslog(LOG_NOTICE,"register ver. 5 - end + space info"); #endif hdd_get_space(&usedspace,&totalspace,&chunkcount,&tdusedspace,&tdtotalspace,&tdchunkcount); buff = masterconn_create_attached_packet(eptr,CSTOMA_REGISTER,1+8+8+4+8+8+4); put8bit(&buff,52); put64bit(&buff,usedspace); put64bit(&buff,totalspace); put32bit(&buff,chunkcount); put64bit(&buff,tdusedspace); put64bit(&buff,tdtotalspace); put32bit(&buff,tdchunkcount); } }
//封装向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 } }