00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "gateway_rpc.h"
00019 #include "gateway_prot.h"
00020 #include <netdb.h>
00021 #include <string.h>
00022 #include <stdio.h>
00023
00024 static const int DHT_PORT = 5852;
00025
00027
00028
00029
00030 int
00031 lookup_host(const char* host, int port, struct sockaddr_in* addr)
00032 {
00033 struct hostent* h = gethostbyname (host);
00034 if (h == NULL) return 0;
00035
00036 bzero (addr, sizeof(struct sockaddr_in));
00037 addr->sin_family = AF_INET;
00038 addr->sin_port = htons(port);
00039
00040
00041
00042 memcpy(&addr->sin_addr, h->h_addr, sizeof(struct in_addr));
00043 return 1;
00044 }
00045
00046
00047
00048 CLIENT*
00049 get_connection(struct sockaddr_in* addr)
00050 {
00051 int sockp = RPC_ANYSOCK;
00052 CLIENT * c = clnttcp_create(addr, BAMBOO_DHT_GATEWAY_PROGRAM,
00053 BAMBOO_DHT_GATEWAY_VERSION, &sockp, 0, 0);
00054 return c;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 int
00072 do_null_op(CLIENT* c)
00073 {
00074 void* null_args = NULL;
00075 void* res = bamboo_dht_proc_null_2(&null_args, c);
00076 return (res != NULL);
00077 }
00078
00079
00080
00081
00082 int
00083 test_node(const char* hostname, struct sockaddr_in* addr)
00084 {
00085 printf(" testing dht node %s... ", hostname);
00086
00087
00088 if (!lookup_host(hostname, DHT_PORT, addr))
00089 {
00090 printf("lookup_host failed\n");
00091 return 0;
00092 }
00093
00094
00095
00096
00097 CLIENT* p_client = get_connection(addr);
00098 if (p_client == NULL)
00099 {
00100 printf("get_connection failed\n");
00101 return 0;
00102 }
00103
00104
00105 if (!do_null_op(p_client))
00106 {
00107 printf("null_op failed\n");
00108 clnt_destroy(p_client);
00109 return 0;
00110 }
00111
00112 printf("succeeded.\n");
00113 clnt_destroy(p_client);
00114 return 1;
00115 }