]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_networkclient.c
don't treat 0.0.0.0 as ip, take the nodename for the lookup instead.
[citadel.git] / citadel / modules / network / serv_networkclient.c
index 839818efb2f74986cf91bea8ce73de6eaf3c72e4..5843ae62db8fede71d2a7ad57d9d6e6d0aafa9c1 100644 (file)
@@ -135,8 +135,6 @@ void DeleteNetworker(void *vptr)
        FreeStrBuf(&NW->port);
        FreeStrBuf(&NW->secret);
        FreeStrBuf(&NW->Url);
-       ((struct CitContext*)NW->IO.CitContext)->state = CON_IDLE;
-       ((struct CitContext*)NW->IO.CitContext)->kill_me = 1;
        FreeAsyncIOContents(&NW->IO);
        free(NW);
 }
@@ -623,8 +621,6 @@ eNextState nwc_get_one_host_ip(AsyncIO *IO)
         * here we start with the lookup of one host.
         */ 
 
-       InitC_ares_dns(IO);
-
        syslog(LOG_DEBUG, "NWC: %s\n", __FUNCTION__);
 
        syslog(LOG_DEBUG, 
@@ -789,36 +785,31 @@ eNextState nwc_connect_ip(AsyncIO *IO)
               ChrPtr(NW->host),
               ChrPtr(NW->port));
        
-       return InitEventIO(IO, NW, 
-                          NWC_ConnTimeout, 
-                          NWC_ReadTimeouts[0],
-                          1);
+       return EvConnectSock(IO,
+                            NWC_ConnTimeout,
+                            NWC_ReadTimeouts[0],
+                            1);
 }
 
 void RunNetworker(AsyncNetworker *NW)
 {
-       CitContext *SubC;
-
        ParseURL(&NW->IO.ConnectMe, NW->Url, 504);
 
-       NW->IO.Data          = NW;
-       NW->IO.SendDone      = NWC_DispatchWriteDone;
-       NW->IO.ReadDone      = NWC_DispatchReadDone;
-       NW->IO.Terminate     = NWC_Terminate;
-       NW->IO.LineReader    = NWC_ReadServerStatus;
-       NW->IO.ConnFail      = NWC_ConnFail;
-       NW->IO.DNSFail       = NWC_DNSFail;
-       NW->IO.Timeout       = NWC_Timeout;
-       NW->IO.ShutdownAbort = NWC_Shutdown;
-       
-       NW->IO.SendBuf.Buf   = NewStrBufPlain(NULL, 1024);
-       NW->IO.RecvBuf.Buf   = NewStrBufPlain(NULL, 1024);
-       NW->IO.IOBuf         = NewStrBuf();
-       
-       NW->IO.NextState     = eReadMessage;
-       SubC = CloneContext (&networker_client_CC);
-       SubC->session_specific_data = (char*) NW;
-       NW->IO.CitContext = SubC;
+       InitIOStruct(&NW->IO,
+                    NW,
+                    eReadMessage,
+                    NWC_ReadServerStatus,
+                    NWC_DNSFail,
+                    NWC_DispatchWriteDone,
+                    NWC_DispatchReadDone,
+                    NWC_Terminate,
+                    NWC_ConnFail,
+                    NWC_Timeout,
+                    NWC_Shutdown);
+
+       safestrncpy(((CitContext *)NW->IO.CitContext)->cs_host, 
+                   ChrPtr(NW->host),
+                   sizeof(((CitContext *)NW->IO.CitContext)->cs_host)); 
 
        if (NW->IO.ConnectMe->IsIP) {
                QueueEventContext(&NW->IO,
@@ -850,6 +841,8 @@ void network_poll_other_citadel_nodes(int full_poll, char *working_ignetcfg)
                syslog(LOG_DEBUG, "network: no neighbor nodes are configured - not polling.\n");
                return;
        }
+       become_session(&networker_client_CC);
+
        CfgData = NewStrBufPlain(working_ignetcfg, -1);
        Line = NewStrBufPlain(NULL, StrLength(CfgData));
        Done = 0;
@@ -895,10 +888,17 @@ void network_poll_other_citadel_nodes(int full_poll, char *working_ignetcfg)
                        }
                        if (poll) {
                                NW->Url = NewStrBufPlain(NULL, StrLength(Line));
-                               StrBufPrintf(NW->Url, "citadel://:%s@%s:%s", 
-                                            ChrPtr(NW->secret),
-                                            ChrPtr(NW->host),
-                                            ChrPtr(NW->port));
+                               if ((StrLength (NW->host) > NULL) && (!strcmp(NW->host, "0.0.0.0")))
+                                       StrBufPrintf(NW->Url, "citadel://:%s@%s:%s", 
+                                                    ChrPtr(NW->secret),
+                                                    ChrPtr(NW->host),
+                                                    ChrPtr(NW->port));
+                               else
+                                       StrBufPrintf(NW->Url, "citadel://:%s@%s:%s", 
+                                                    ChrPtr(NW->secret),
+                                                    ChrPtr(NW->node),
+                                                    ChrPtr(NW->port));
+
                                if (!network_talking_to(SKEY(NW->node), NTT_CHECK))
                                {
                                        network_talking_to(SKEY(NW->node), NTT_ADD);