src/Reporter.c
/*
 * InitReport is called by a transfer agent (client or
 * server) to setup the needed structures to communicate
 * traffic.
 */
InitReport is called by a transfer agent (client or
server) to setup the needed structures to communicate
traffic.
InitReport is called by a transfer agent ( client or server ) to setup the needed structures to communicate traffic .
ReportHeader* InitReport( thread_Settings *agent ) {
    ReportHeader *reporthdr = NULL;
    ReporterData *data = NULL;
    if ( isDataReport( agent ) ) {
        reporthdr = malloc( sizeof(ReportHeader) +
                            NUM_REPORT_STRUCTS * sizeof(ReportStruct) );
        if ( reporthdr != NULL ) {
            memset( reporthdr, 0, sizeof(ReportHeader));
            reporthdr->data = (ReportStruct*)(reporthdr+1);
            reporthdr->multireport = agent->multihdr;
            data = &reporthdr->report;
            reporthdr->reporterindex = NUM_REPORT_STRUCTS - 1;
            data->info.transferID = agent->mSock;
            data->info.groupID = (agent->multihdr != NULL ? agent->multihdr->groupID : -1);
            data->type = TRANSFER_REPORT;
            if ( agent->mInterval != 0.0 ) {
                struct timeval *interval = &data->intervalTime;
                interval->tv_sec = (long) agent->mInterval;
                interval->tv_usec = (long) ((agent->mInterval - interval->tv_sec) * rMillion);
            }
            data->mHost = agent->mHost;
            data->mLocalhost = agent->mLocalhost;
            data->mBufLen = agent->mBufLen;
            data->mMSS = agent->mMSS;
            data->mTCPWin = agent->mTCPWin;
            data->flags = agent->flags;
            data->mThreadMode = agent->mThreadMode;
            data->mode = agent->mReportMode;
            data->info.mFormat = agent->mFormat;
            data->info.mTTL = agent->mTTL;
	    if (data->mThreadMode == kMode_Server)
		data->info.tcp.read.binsize = data->mBufLen / 8;
            if ( isUDP( agent ) ) {
		gettimeofday(&data->IPGstart, NULL);
                reporthdr->report.info.mUDP = (char)agent->mThreadMode;
            } else {
                reporthdr->report.info.mTCP = (char)agent->mThreadMode;
	    }
	    if ( isEnhanced( agent ) ) {
		data->info.mEnhanced = 1;
	    } else {
		data->info.mEnhanced = 0;
	    }
        } else {
            FAIL(1, "Out of Memory!!\n", agent);
        }
    }
    if ( isConnectionReport( agent ) ) {
        if ( reporthdr == NULL ) {
            reporthdr = malloc( sizeof(ReportHeader) );
            if ( reporthdr != NULL ) {
                memset( reporthdr, 0, sizeof(ReportHeader));
                data = &reporthdr->report;
                data->info.transferID = agent->mSock;
                data->info.groupID = -1;
            } else {
                FAIL(1, "Out of Memory!!\n", agent);
            }
        }
        if ( reporthdr != NULL ) {
            data->type |= CONNECTION_REPORT;
            data->connection.peer = agent->peer;
            data->connection.size_peer = agent->size_peer;
            data->connection.local = agent->local;
            data->connection.size_local = agent->size_local;
	    data->connection.peerversion = agent->peerversion;
        } else {
            FAIL(1, "Out of Memory!!\n", agent);
        }
    }
    if ( isConnectionReport( agent ) || isDataReport( agent ) ) {
#ifdef HAVE_THREAD
        if ( reporthdr->report.mThreadMode == kMode_Client &&
             reporthdr->multireport != NULL ) {
            BarrierClient( reporthdr );
        } else {
            if ( reporthdr->multireport != NULL && isMultipleReport( agent )) {
                reporthdr->multireport->threads++;
                if ( reporthdr->multireport->report->startTime.tv_sec == 0 ) {
                    gettimeofday( &(reporthdr->multireport->report->startTime), NULL );
                }
                reporthdr->report.startTime = reporthdr->multireport->report->startTime;
            } else {
                gettimeofday( &(reporthdr->report.startTime), NULL );
            }
            reporthdr->report.nextTime = reporthdr->report.startTime;
            TimeAdd( reporthdr->report.nextTime, reporthdr->report.intervalTime );
        }
        Condition_Lock( ReportCond );
        reporthdr->next = ReportRoot;
        ReportRoot = reporthdr;
        Condition_Signal( &ReportCond );
        Condition_Unlock( ReportCond );
#else
        gettimeofday( &(reporthdr->report.startTime), NULL );
	reporthdr->report.nextTime = reporthdr->report.startTime;
	TimeAdd( reporthdr->report.nextTime, reporthdr->report.intervalTime );
        reporthdr->next = NULL;
        process_report ( reporthdr );
#endif
    }
    if ( !isDataReport( agent ) ) {
        reporthdr = NULL;
    }
    return reporthdr;
}
ReportHeader * InitReport ( thread_Settings * agent ) { ReportHeader * reporthdr = NULL ; ReporterData * data = NULL ; if ( isDataReport ( agent ) ) { reporthdr = malloc ( sizeof ( ReportHeader ) + NUM_REPORT_STRUCTS * sizeof ( ReportStruct ) ) ; if ( reporthdr != NULL ) { memset ( reporthdr , 0 , sizeof ( ReportHeader ) ) ; reporthdr -> data = ( ReportStruct * ) ( reporthdr + 1 ) ; reporthdr -> multireport = agent -> multihdr ; data = & reporthdr -> report ; reporthdr -> reporterindex = NUM_REPORT_STRUCTS - 1 ; data -> info . transferID = agent -> mSock ; data -> info . groupID = ( agent -> multihdr != NULL ? agent -> multihdr -> groupID : -1 ) ; data -> type = TRANSFER_REPORT ; if ( agent -> mInterval != 0.0 ) { struct timeval * interval = & data -> intervalTime ; interval -> tv_sec = ( long ) agent -> mInterval ; interval -> tv_usec = ( long ) ( ( agent -> mInterval - interval -> tv_sec ) * rMillion ) ; } data -> mHost = agent -> mHost ; data -> mLocalhost = agent -> mLocalhost ; data -> mBufLen = agent -> mBufLen ; data -> mMSS = agent -> mMSS ; data -> mTCPWin = agent -> mTCPWin ; data -> flags = agent -> flags ; data -> mThreadMode = agent -> mThreadMode ; data -> mode = agent -> mReportMode ; data -> info . mFormat = agent -> mFormat ; data -> info . mTTL = agent -> mTTL ; if ( data -> mThreadMode == kMode_Server ) data -> info . tcp . read . binsize = data -> mBufLen / 8 ; if ( isUDP ( agent ) ) { gettimeofday ( & data -> IPGstart , NULL ) ; reporthdr -> report . info . mUDP = ( char ) agent -> mThreadMode ; } else { reporthdr -> report . info . mTCP = ( char ) agent -> mThreadMode ; } if ( isEnhanced ( agent ) ) { data -> info . mEnhanced = 1 ; } else { data -> info . mEnhanced = 0 ; } } else { FAIL ( 1 , " \n " , agent ) ; } } if ( isConnectionReport ( agent ) ) { if ( reporthdr == NULL ) { reporthdr = malloc ( sizeof ( ReportHeader ) ) ; if ( reporthdr != NULL ) { memset ( reporthdr , 0 , sizeof ( ReportHeader ) ) ; data = & reporthdr -> report ; data -> info . transferID = agent -> mSock ; data -> info . groupID = -1 ; } else { FAIL ( 1 , " \n " , agent ) ; } } if ( reporthdr != NULL ) { data -> type |= CONNECTION_REPORT ; data -> connection . peer = agent -> peer ; data -> connection . size_peer = agent -> size_peer ; data -> connection . local = agent -> local ; data -> connection . size_local = agent -> size_local ; data -> connection . peerversion = agent -> peerversion ; } else { FAIL ( 1 , " \n " , agent ) ; } } if ( isConnectionReport ( agent ) || isDataReport ( agent ) ) { #ifdef HAVE_THREAD if ( reporthdr -> report . mThreadMode == kMode_Client && reporthdr -> multireport != NULL ) { BarrierClient ( reporthdr ) ; } else { if ( reporthdr -> multireport != NULL && isMultipleReport ( agent ) ) { reporthdr -> multireport -> threads ++ ; if ( reporthdr -> multireport -> report -> startTime . tv_sec == 0 ) { gettimeofday ( & ( reporthdr -> multireport -> report -> startTime ) , NULL ) ; } reporthdr -> report . startTime = reporthdr -> multireport -> report -> startTime ; } else { gettimeofday ( & ( reporthdr -> report . startTime ) , NULL ) ; } reporthdr -> report . nextTime = reporthdr -> report . startTime ; TimeAdd ( reporthdr -> report . nextTime , reporthdr -> report . intervalTime ) ; } Condition_Lock ( ReportCond ) ; reporthdr -> next = ReportRoot ; ReportRoot = reporthdr ; Condition_Signal ( & ReportCond ) ; Condition_Unlock ( ReportCond ) ; #else gettimeofday ( & ( reporthdr -> report . startTime ) , NULL ) ; reporthdr -> report . nextTime = reporthdr -> report . startTime ; TimeAdd ( reporthdr -> report . nextTime , reporthdr -> report . intervalTime ) ; reporthdr -> next = NULL ; process_report ( reporthdr ) ; #endif } if ( ! isDataReport ( agent ) ) { reporthdr = NULL ; } return reporthdr ; }
InitReport is called by a transfer agent (client or
 server) to setup the needed structures to communicate
 traffic.
InitReport is called by a transfer agent ( client or server ) to setup the needed structures to communicate traffic .
/*
         * Create in one big chunk
         */ // Only need to make sure the headers are clean /*
             * Create in one big chunk
             */ // Only need to make sure the headers are clean /*
         * Update the ReportRoot to include this report.
         */ // syncronize watches on my mark...... // set start time // set start time // set next report time /*
         * Process the report in this thread
         */