Ignore:
Timestamp:
Jan 22, 2011, 12:57:36 AM (11 years ago)
Author:
schwittmann
Message:

Several ExternalClient improvements:

  • Separated connected and request job events
  • Added basic authentication
  • Lookup DNS again after getting disconnected
  • Fixed some socket exceptions
  • Prevent slow clients from submitting old jobs by using unique job identifiers
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Main.cpp

    r2205 r2417  
    1616void usage(char **argv)
    1717{
    18     printf("Usage: %s $THREAD_NUM $HOST $PORT\n\n", argv[0]);
    19     printf("    THREAD_NUM - Number of concurrent threads\n");
     18    printf("Usage: %s $HOST $PORT [$PASSWORD]\n\n", argv[0]);
    2019    printf("    HOST       - PC running cryptool\n");
    2120    printf("    PORT       - Cryptool's listening port\n");
     21    printf("    [PASSWORD] - Password used to auth with server\n");
    2222}
    2323
    24 int threadNum;
     24bool lookup(const char* host, sockaddr_in & serv_addr)
     25{
     26    hostent *server = gethostbyname(host);
    2527
     28    if(!server)
     29        return false;
     30
     31    serv_addr.sin_family = AF_INET;
     32    bcopy((char *)server->h_addr,
     33            (char *)&serv_addr.sin_addr.s_addr,
     34            server->h_length);
     35
     36    return true;
     37}
    2638
    2739int main (int argc, char **argv)
    2840{
    29     if(argc != 4)
     41    if(argc != 3 && argc != 4)
    3042    {
    3143        usage(argv);
     
    3345    }
    3446
    35     threadNum = atoi(argv[1]);
    36     if(threadNum== 0)
     47    const char* password = "";
     48    if(argc == 4)
    3749    {
    38         printf("Invalid number of threads\n");
    39         return 1;
     50        password = argv[3];
    4051    }
    4152
    42     hostent *server = gethostbyname(argv[2]);
    43     if(!server)
    44     {
    45         printf("Invalid host\n");
    46         return 1;
    47     }
    48 
    49     int port = atoi(argv[3]);
     53    int port = atoi(argv[2]);
    5054
    5155    if(port == 0 || port <= 0 || port > 0xFFFF)
     
    5761    sockaddr_in serv_addr;
    5862    bzero((char *) &serv_addr, sizeof(serv_addr));
    59     serv_addr.sin_family = AF_INET;
    60     bcopy((char *)server->h_addr,
    61             (char *)&serv_addr.sin_addr.s_addr,
    62             server->h_length);
    6363    serv_addr.sin_port = htons(port);
     64
    6465    while(true)
    6566    {
    66         networkThread(serv_addr, port);
     67        if(!lookup(argv[1], serv_addr))
     68        {
     69            printf("failed to lookup %s..\n", argv[1]);
     70            continue;
     71        }
     72        networkThread(serv_addr, port, password);
    6773        printf("Reconnecting in %u seconds\n", RECONNECT_TIME);
    6874        sleep(RECONNECT_TIME);
Note: See TracChangeset for help on using the changeset viewer.