Example #1
0
void privEndTest()
{
	if (0 == status.num_failures)
	{
		network_printf("Test %d passed (%lld subtests)\n", number_of_tests, status.num_subtests);
	}
	else
	{
		network_printf("Test %d failed (%lld subtests, %lld failures)\n", number_of_tests, status.num_subtests, status.num_failures);
	}
}
Example #2
0
void network_init()
{
	struct sockaddr_in my_name;

	my_name.sin_family = AF_INET;
	my_name.sin_port = htons(SERVER_PORT);
	my_name.sin_addr.s_addr = htonl(INADDR_ANY);

	net_init();

	server_socket = net_socket(AF_INET, SOCK_STREAM, 0);
	int yes = 1;
	net_setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));

	while(net_bind(server_socket, (struct sockaddr*)&my_name, sizeof(my_name)) < 0)
	{
	}

	net_listen(server_socket, 0);

	struct sockaddr_in client_info;
	socklen_t ssize = sizeof(client_info);
	client_socket = net_accept(server_socket, (struct sockaddr*)&client_info, &ssize);

	network_printf("Hello world!\n");
}
void MFNWorkunitNetworkClient::ImportWorkunitsFromProtobuf(std::string &protobufData) {
    // We've been provided a protobuf!  Import it!
    struct MFNWorkunitRobustElement Workunit;

    // This will get called from inside GetNextWorkunits, with the main mutex
    // already locked.
    this->WorkunitProtobufMutex.lock();
    
    this->WorkunitGroupProtobuf.Clear();
    this->WorkunitGroupProtobuf.ParseFromString(protobufData);
    
    // If the server has requested we wait, do so.
    if (this->WorkunitGroupProtobuf.workunit_wait()) {
        this->returnWaitWorkunit = 1;
    }
    // If the server has requested we terminate the task, do so.
    if (this->WorkunitGroupProtobuf.no_more_workunits()) {
        this->returnWaitWorkunit = 0;
        this->returnTerminateWorkunit = 1;
    }
    
    network_printf("Received %d workunits!\n", this->WorkunitGroupProtobuf.workunits_size());
    for (int i = 0; i < this->WorkunitGroupProtobuf.workunits_size(); i++) {
        memset(&Workunit, 0, sizeof(Workunit));
        this->WorkunitSingleProtobuf.Clear();
        this->WorkunitSingleProtobuf = this->WorkunitGroupProtobuf.workunits(i);
        
        Workunit.WorkUnitID = this->WorkunitSingleProtobuf.workunit_id();
        Workunit.StartPoint = this->WorkunitSingleProtobuf.start_point();
        Workunit.EndPoint = this->WorkunitSingleProtobuf.end_point();
        Workunit.IsValid = 1;
        Workunit.PasswordLength = this->WorkunitSingleProtobuf.password_length();
        Workunit.WorkunitAdditionalData = 
                std::vector<uint8_t>(this->WorkunitSingleProtobuf.additional_data().begin(), 
                this->WorkunitSingleProtobuf.additional_data().end());
        Workunit.WorkunitRequestedTimestamp = this->WorkunitSingleProtobuf.workunit_requested_timestamp();
        // If words are loaded, unpack them.
        if (this->WorkunitSingleProtobuf.number_words_loaded()) {
            Workunit.NumberWordsLoaded = this->WorkunitSingleProtobuf.number_words_loaded();
            Workunit.WordBlockLength = this->WorkunitSingleProtobuf.wordlist_block_length();
            Workunit.WordLengths = 
                std::vector<uint8_t>(this->WorkunitSingleProtobuf.wordlist_lengths().begin(), 
                this->WorkunitSingleProtobuf.wordlist_lengths().end());
            // Handle the 32-bit data specially.
            // Resize to the proper length, zero-filled.
            Workunit.WordlistData.resize(this->WorkunitSingleProtobuf.wordlist_data().length() / 4, 0);
            // Copy the data into place.
            memcpy(&Workunit.WordlistData[0], this->WorkunitSingleProtobuf.wordlist_data().c_str(),
                    this->WorkunitSingleProtobuf.wordlist_data().length());
        }
        this->pendingWorkunits.push_back(Workunit);
    }
    this->WorkunitSingleProtobuf.Clear();
    this->WorkunitGroupProtobuf.Clear();
    
    this->WorkunitProtobufMutex.unlock();
}
Example #4
0
void privDoTest(bool condition, const char* file, int line, const char* fail_msg, ...)
{
	va_list arglist;
	va_start(arglist, fail_msg);

	++status.num_subtests;

	if (condition)
	{
		++status.num_passes;
	}
	else
	{
		++status.num_failures;

		// TODO: vprintf forwarding doesn't seem to work?
		network_printf("Subtest %lld failed in %s on line %d: ", status.num_subtests, file, line);
		network_vprintf(fail_msg, arglist);
		network_printf("\n");
	}
	va_end(arglist);
}
struct MFNWorkunitRobustElement MFNWorkunitNetworkClient::GetNextWorkunit(uint32_t NetworkClientId) {
    trace_printf("MFNWorkunitNetworkClient::GetNextWorkunit(%u)\n", NetworkClientId);

    struct MFNWorkunitRobustElement Workunit;

    this->workunitMutexBoost.lock();
    
    if (this->pendingWorkunits.size() == 0) {
        network_printf("No workunits - trying to fetch 10.\n");
        MultiforcerGlobalClassFactory.getNetworkClientClass()->
                fetchWorkunits(MFN_NETWORK_WORKUNIT_NUMBER_WUS_TO_FETCH, 
                this->CurrentPasswordLength);
        network_printf("pending size: %d\n", this->pendingWorkunits.size());
    }

    // Check to see if there are valid workunits left.
    if (this->pendingWorkunits.size() == 0) {
        // If not, return a unit with the specified flags.
        if (this->DebugOutput) {
            printf("pendingWorkunits.size() == 0; returning.\n");
        }
        memset(&Workunit, 0, sizeof(MFNWorkunitRobustElement));
        // Set the flags specified if needed.
        if (this->returnWaitWorkunit) {
            Workunit.Flags = WORKUNIT_DELAY;
        } else if (this->returnTerminateWorkunit) {
            Workunit.Flags = WORKUNIT_TERMINATE;
        }
        // Otherwise, return a null workunit, which is a term signal too.
        this->workunitMutexBoost.unlock();
        if (this->DebugOutput) {
            PrintRobustWorkunit(Workunit);
        }
        return Workunit;
    }

    // We still have workunits left.

    // Get the next waiting workunit from the main queue.
    Workunit = this->pendingWorkunits.front();
    this->pendingWorkunits.pop_front();

    if (this->DebugOutput) {
        printf("Popped WU ID %lu\n", Workunit.WorkUnitID);
    }

    // Set some variables we can make use of.
    Workunit.IsAssigned = 1;

    // Add the workunit to the in-flight queue.
    this->assignedWorkunits.push_back(Workunit);
    if (this->DebugOutput) {
        printf("In flight WUs: %lu\n", this->assignedWorkunits.size());
    }  

    this->workunitMutexBoost.unlock();
    if (this->DebugOutput) {
        PrintRobustWorkunit(Workunit);
    }
    return Workunit;
}