Example #1
0
int main(int argc, char **argv)
{
	struct producer_config pc;
	struct consumer_config cc;
	struct flow_table flowtable;
	pthread_t tid[4];
	int i;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <network_interface>\n", argv[0]);
		fprintf(stderr, "For example: %s eth0\n", argv[0]);
		fprintf(stderr, "\t see %s for results\n", EU_LOG);
		return ERROR;
	}

	if(setup_packet_capture(&pc, argv[1], NETFILTER) != 0){
		fprintf(stderr, "%s: error setting up packet capture interface!\n", argv[0]);
		return ERROR;
	}

	if(listen_for_requests(&cc, SERVER_PORT) != 0){
		fprintf(stderr, "%s: error listening for client requests!\n", argv[0]);
		return ERROR;
	}

	if ((cc.model = svm_load_model(model_file)) == 0) {
		fprintf(stderr, "could not open model file %s\n", model_file);
		return ERROR;
	}

	signal(SIGINT, siginthandler);
	signal(SIGPIPE, SIG_IGN);
#ifdef EU_STATS
	signal(SIGALRM, sigalarmhandler);
	alarm(STAT_TIME);
	memset(&stats, 0, sizeof(struct eu_stats));
	cc.stats= &stats; pc.stats= &stats;
	pthread_mutex_init(&(update_mutex), NULL);
	cc.update_mutex= &update_mutex; pc.update_mutex= &update_mutex;
#endif

	/* everything is sent in network byte order */
	cc.n_max_payload = htonl(MAX_PAYLOAD);

	/* initialize tables and stuff */
	flowtable_init(&flowtable, FLOW_ENTRIES);
	cc.keep_going= &keep_going; pc.keep_going= &keep_going;
	cc.flowtable= &flowtable; pc.flowtable= &flowtable;

	if ((cc.x =
	     (struct svm_node *)malloc(max_nr_attr *
				       sizeof(struct svm_node))) == NULL) {
		fprintf(stderr, "could not allocate memory for svm_node!\n");
		flowtable_finit(&flowtable);
		svm_destroy_model(cc.model);
		close_pcap_interface(&pc.pcap);
		return 1;
	}

	/* let the games begin! */
	if (pthread_create(&tid[0], NULL, accept_connections_for_flows, (void *)&cc) != 0) {
		fprintf(stderr, "%s: could not spawn thread\n", argv[0]);
		return ERROR;
	}

	if (pthread_create(&tid[1], NULL, produce_flowtable, (void *)&pc) != 0) {
		fprintf(stderr, "could not spawn thread\n");
		return ERROR;
	}

	consume_flowtable(&cc);

	fprintf(stderr, "waiting for threads to quit....\n");
	/* done with everything */
	for(i=0; i < 2; ++i)
		if (pthread_join(tid[i], NULL) != 0)
			fprintf(stderr, "%s: error waiting for thread %ld\n", argv[0], tid[i]);

	svm_destroy_model(cc.model);
	flowtable_finit(&flowtable);

	print_pcap_stats(stdout, &pc.pcap);
	close_pcap_interface(&pc.pcap);

	return 0;
}
Example #2
0
int main(int argc, char **argv)
{
	struct producer_config pc;
	struct consumer_config cc;
	struct flow_table flowtable;
	pthread_t tid[4];

	if (argc != 2) {
		fprintf(stderr, "usage: %s <model-file>\n", argv[0]);
		return STATUS_ERROR;
	}

	if (setup_packet_capture(&pc, SENSOR_NETFILTER) != STATUS_OK) {
		fprintf(stderr, "%s: could not setup packet capture interface!\n", argv[0]);
		return STATUS_ERROR;
	}

	if (listen_for_requests(&cc, SENSOR_LISTEN_PORT) != STATUS_OK) {
		fprintf(stderr, "%s: error listening for client requests!\n", argv[0]);
		return STATUS_ERROR;
	}

	if ((cc.model = svm_load_model(argv[1])) == 0) {
		fprintf(stderr, "%s: could not open model file %s\n", argv[0], argv[1]);
		return STATUS_ERROR;
	}

	/* everything is sent in network byte order */
	cc.n_max_payload = htonl(PAYLOAD_BUFFER_LENGTH);

	/* initialize tables and stuff */
	flowtable_init(&flowtable, FLOWTABLE_BUCKETS, FLOWTABLE_RECORDS);
	cc.keep_going = &keep_going;
	pc.keep_going = &keep_going;
	cc.flowtable = &flowtable;
	pc.flowtable = &flowtable;

	if ((cc.x = (struct svm_node *)malloc(max_nr_attr * sizeof(struct svm_node))) == NULL) {
		fprintf(stderr, "%s: could not allocate memory for classifier!\n", argv[0]);
		flowtable_finit(&flowtable);
		svm_destroy_model(cc.model);
		close_pcap_interface(&pc.pcap);
		return STATUS_ERROR;
	}

	signal(SIGINT, siginthandler);
	signal(SIGPIPE, SIG_IGN);

	/* let the games begin! */
	if (pthread_create(&tid[0], NULL, produce_flowtable, (void *)&pc) != 0) {
		fprintf(stderr, "%s: could not spawn thread!\n", argv[0]);
		return STATUS_ERROR;
	}

	if (pthread_create(&tid[1], NULL, accept_connections_for_flows, (void *)&cc) != 0) {
		fprintf(stderr, "%s: could not spawn thread\n", argv[0]);
		return STATUS_ERROR;
	}

	consume_flowtable((void *)&cc);
	flowtable_finit(&flowtable);
	print_pcap_stats(stderr, &pc.pcap);
	close_pcap_interface(&pc.pcap);

	return STATUS_OK;
}
Example #3
0
/**
* Main
* @param  argc  number of arguments
* @param  argv  array of arguments
* @return   boolean success or failure
*/
int main(int argc, char* argv[])
{
  if(argc > 1)
  {
    if( (strstr(argv[1], "new") != NULL) )
    {
      if(argc < 4)
      {
        printf("Please enter a filename and a tracker url\n");
        exit(1);
      }
      else
      {
        MetaData* newTorrent;
        newTorrent = create_meta_file(argv[2], argv[3]);
      }
    }
    else if( (strstr(argv[1], "read")) )
    {
      if(argc != 3)
      {
        printf("Please enter the name of a torrent file!\n");
        exit(1);
      }
      else
      {
        MetaData* curTorrent;
        curTorrent = parse_meta_file(argv[2]);
        print_MetaData(curTorrent, FALSE);
      }
    }
    else if( (strstr(argv[2], "start")) )
    {
      if(argc != 4)
      {
        printf("Invalid arguments.\n  Proper usage:\n   client.o name:port start filename.trrnt\n");
        exit(1);
      }
      else
      {
        parse_host_info(argv[1], myHostName, &myPort);
        printf("Using HostName: %s:%i\n", myHostName, myPort);

        MetaData* curTorrent;
        curTorrent = parse_meta_file(argv[3]);
        
        pthread_t threads[2];
        // Listen for requests
        pthread_create(&(threads[0]), NULL, request_listener_thread, NULL);
        // Start the download
        pthread_create(&(threads[1]), NULL, download_manager_thread, (void*)curTorrent);
        
        //sync on the threads
        pthread_join(threads[0], NULL);
        pthread_join(threads[1], NULL);

        linkedList_free_ts(threadPool);
        pthread_cond_destroy(&threadPoolCondition);
      }
    }
    else if( (strstr(argv[2], "listen")) )
    {
      if( !(argc == 3 || argc == 5) )
      {
        printf("Invalid arguments. Please enter a port and/or hostname.\n");
        exit(1);
      }
      else
      {
        parse_host_info(argv[1], myHostName, &myPort);
        printf("Using HostName: %s:%i\n", myHostName, myPort);
        
        if( (argc == 5 && strstr(argv[3], "tracker") != NULL) )
        {
            char trackerName[255];
            int trackerPort;
            parse_host_info(argv[4], trackerName, &trackerPort);
            broadcast_finished_files(trackerName, trackerPort);
        }

        listen_for_requests();
      }
    }
  }
}
Example #4
0
int main(int argc, char **argv)
{
	struct producer_config pc;
	struct consumer_config cc;
	struct flow_table flowtable;
	pthread_t tid[4];

	if (argc != 2) {
		fprintf(stderr, "usage: %s <model-file>\n", argv[0]);
		return ERROR;
	}

	if (setup_packet_capture(&pc, NETFILTER) != 0) {
		fprintf(stderr,
			"%s: error setting up packet capture interface!\n",
			argv[0]);
		return ERROR;
	}

	if (listen_for_requests(&cc, SERVER_PORT) != 0) {
		fprintf(stderr, "%s: error listening for client requests!\n",
			argv[0]);
		return ERROR;
	}

	if ((cc.model = svm_load_model(argv[1])) == 0) {
		fprintf(stderr, "could not open model file %s\n", argv[1]);
		return ERROR;
	}

	/* everything is sent in network byte order */
	cc.n_max_payload = htonl(MAX_PAYLOAD);

	/* initialize tables and stuff */
	flowtable_init(&flowtable, FLOW_ENTRIES);
	cc.keep_going = &keep_going;
	pc.keep_going = &keep_going;
	cc.flowtable = &flowtable;
	pc.flowtable = &flowtable;

	if ((cc.x =
	     (struct svm_node *)malloc(max_nr_attr *
				       sizeof(struct svm_node))) == NULL) {
		fprintf(stderr, "could not allocate memory for svm_node!\n");
		flowtable_finit(&flowtable);
		svm_destroy_model(cc.model);
		close_pcap_interface(&pc.pcap);
		return 1;
	}

	if (init_send_buffers(&cc.sb, SEND_BUFFER_SIZE, SEND_BUFFERS) != 0) {
		fprintf(stderr, "could not initialize send buffers!\n");
		free(cc.x);
		flowtable_finit(&flowtable);
		svm_destroy_model(cc.model);
		close_pcap_interface(&pc.pcap);
		return 1;
	}

	signal(SIGINT, siginthandler);
	signal(SIGPIPE, SIG_IGN);

	/* let the games begin! */
	if (pthread_create(&tid[0], NULL, produce_flowtable, (void *)&pc) != 0) {
		fprintf(stderr, "could not spawn thread\n");
		return ERROR;
	}

	if (pthread_create(&tid[1], NULL, consume_flowtable, (void *)&cc) != 0) {
		fprintf(stderr, "could not spawn thread\n");
		return ERROR;
	}

	if (pthread_create
	    (&tid[2], NULL, accept_connections_for_flows, (void *)&cc) != 0) {
		fprintf(stderr, "%s: could not spawn thread\n", argv[0]);
		return ERROR;
	}
#if 0
	if (pthread_create(&tid[3], NULL, write_to_clients, (void *)&cc) != 0) {
		fprintf(stderr, "could not spawn thread\n");
		return ERROR;
	}
	/* done with everything */
	for (i = 0; i < 4; ++i)
		if (pthread_join(tid[i], NULL) != 0)
			fprintf(stderr, "%s: error waiting for thread %ld\n",
				argv[0], tid[i]);
#endif
	write_to_clients((void *)&cc);
	svm_destroy_model(cc.model);
	flowtable_finit(&flowtable);

	print_pcap_stats(stdout, &pc.pcap);
	close_pcap_interface(&pc.pcap);

	return 0;
}
Example #5
0
void* request_listener_thread(void* arg)
{
  listen_for_requests();
  pthread_exit(NULL);
}