Exemplo n.º 1
0
void masterconn_metachanges_log(masterconn *eptr,const uint8_t *data,uint32_t length) {
    char line[1024];
    uint64_t version;
    if (length==1 && data[0]==0x55) {
        fs_storeall(1);
        return;
    }
    if (length<10) {
        syslog(LOG_NOTICE,"MATOML_METACHANGES_LOG - wrong size (%"PRIu32"/9+data)",length);
        eptr->mode = KILL;
        return;
    }
    if (data[0]!=0xFF) {
        syslog(LOG_NOTICE,"MATOML_METACHANGES_LOG - wrong packet");
        eptr->mode = KILL;
        return;
    }
    if (data[length-1]!='\0') {
        syslog(LOG_NOTICE,"MATOML_METACHANGES_LOG - invalid string");
        eptr->mode = KILL;
        return;
    }

    data++;
    version = get64bit(&data);

    if (version<currentlogversion) {
        syslog(LOG_WARNING, "get old change: %"PRIu64":%"PRIu64", ignore",currentlogversion,version-1);
        return;
    }
    if (currentlogversion>0 && version>currentlogversion) {
        syslog(LOG_WARNING, "some changes lost: [%"PRIu64"-%"PRIu64"], download metadata again",currentlogversion,version-1);
        masterconn_metadownloadinit();
        return;
    }

    if (version == fs_getversion()) {
        changelog(version, "%s", (const char*)data); 
        currentlogversion = version+1;

        sprintf(line, ": %s\n", data);
        if (restore_line("(live changelog)", version, line)!=STATUS_OK) {
            syslog(LOG_WARNING, "replay change log failed: version=%"PRIu64", download metadata again",version);
            masterconn_metadownloadinit();
        } else if (fs_getversion() != version+1) {
            syslog(LOG_WARNING, "restored version not match: %"PRIu64"!=%"PRIu64", download metadata again",fs_getversion(),version+1);
            masterconn_metadownloadinit();
        }
    } else {
        syslog(LOG_WARNING, "version not match: %"PRIu64"!=%"PRIu64", download metadata again",fs_getversion(),version);
        masterconn_metadownloadinit();
    }
}
Exemplo n.º 2
0
void masterconn_connected(masterconn *eptr) {
    tcpnodelay(eptr->sock);
    eptr->mode=HEADER;
    eptr->inputpacket.next = NULL;
    eptr->inputpacket.bytesleft = 8;
    eptr->inputpacket.startptr = eptr->hdrbuff;
    eptr->inputpacket.packet = NULL;
    eptr->outputhead = NULL;
    eptr->outputtail = &(eptr->outputhead);

    masterconn_sendregister(eptr);
    masterconn_metadownloadinit();
    eptr->lastread = eptr->lastwrite = main_time();
}
Exemplo n.º 3
0
//confirm sync thread is ready to transfer metadata
void masterconn_sync_thread(serventry *eptr,const uint8_t *data,uint32_t length) {
	uint8_t flag;
	//serventry *weptr;

    NOT_USED(length);
	flag = get8bit(&data);
	MFSLOG(LOG_NOTICE,"the masterconn_sync_thread flag is %d",flag);
	if (flag == 1) {
		masterconn_metadownloadinit();
	} else if (flag == 2) {
		masterconn_changelog0downloadinit();
	} else if (flag == 3) {
		masterconn_changelog_ready(eptr);
	} else {
		MFSLOG(LOG_NOTICE,"MATOSLA_SYNC_THREAD:unrecognize flag");
	}
	
}
Exemplo n.º 4
0
void masterconn_connected(masterconn *eptr) {
    double now;

    now = monotonic_seconds();
    tcpnodelay(eptr->sock);
    eptr->mode = DATA;
    eptr->lastread = now;
    eptr->lastwrite = now;
    eptr->input_bytesleft = 8;
    eptr->input_startptr = eptr->input_hdr;
    eptr->input_end = 0;
    eptr->input_packet = NULL;
    eptr->inputhead = NULL;
    eptr->inputtail = &(eptr->inputhead);
    eptr->outputhead = NULL;
    eptr->outputtail = &(eptr->outputhead);

    masterconn_sendregister(eptr);
    if (lastlogversion==0) {
        masterconn_metadownloadinit();
    }
}