Hello Nadeem,
thanks for your email. Our next release will contain a version where multiple NSLPs can connect to the NTLP at the same time. You were right, that gimps->sd_unix_socket is overwritten every time a new NSLP connects to the NSLP.
I included a patch for nsis_0.1.1 where this problem is fixed. Here's a short description how to approach:
- the 'gimps->sd_unix_socket' variable is deleted in Gimps.h and in socket_events.cpp - in socket_events.cpp 'gimps->sd_unix_socket' is replaced by 'int socket' which is provided by the its function-call - 'socket' is given to ParseApiMsg (nslp_api/api_server.cpp) that the nslp_id and the socket can be registered using 'gimps->registerNslpApp()' - in RecvMessage() (nslp_api/nslp_api.cpp) we search the list 'Gimps_Nslp_Registry_Entry_t' for the socket using the nslp_id and replace 'gimps->sd_unix_socket' by 'reEntry->sock'
I hope this helps and please don't hesitate to ask further questions.
Bye, Bernd
Xiaoming Fu wrote:
Dear Nadeem,
Thanks for your enquiry.
As you might note in the release note, we encourge people direct all technical questions to the GIMPS/NSIS implementation list (after joining it): https://user.informatik.uni-goettingen.de/mailman/listinfo/nsis_imp
I'm cc-ing to the list for the corresponding people to answer your question.
We appreciate your understanding and collaboration.
Best regards, Xiaoming Fu
N.Akhtar wrote:
Dear Fu, First of all, I would like to congratulate you on developing the GIMPS software. I've been using it over the past couple of weeks. I'm trying to develop a new NSLP but I've a problem. When I start a new NSLP server, the sd_unix_socket variable (in Gimps class) is overwitten (in the unix_socket_connect function). Is this normal? What's the best way to introduce a new NSLP? I would be extremely grateful if you could reply to my question.
Regards, Nadeem
Nadeem Akhtar Centre for Communication Systems Research University of Surrey, Guildford GU2 7XH Surrey, UK.
Phone: +44-1483-683424
Nsis_Imp mailing list Nsis_Imp@informatik.uni-goettingen.de https://user.informatik.uni-goettingen.de/mailman/listinfo/nsis_imp
diff -Naur nsis_0.1.1.bak/Gimps.h nsis_0.1.1/Gimps.h --- nsis_0.1.1.bak/Gimps.h 2005-08-03 11:51:17.000000000 +0200 +++ nsis_0.1.1/Gimps.h 2005-08-21 01:17:37.000000000 +0200 @@ -108,7 +108,6 @@ bool config_useSCTP; bool useEmbeddedPingDaemon;
- int sd_unix_socket; int sd_udp;
GimpsMRSHashTable * msgRoutingStateTable; diff -Naur nsis_0.1.1.bak/nslp_api/api_server.cpp nsis_0.1.1/nslp_api/api_server.cpp --- nsis_0.1.1.bak/nslp_api/api_server.cpp 2005-08-03 11:51:17.000000000 +0200 +++ nsis_0.1.1/nslp_api/api_server.cpp 2005-08-21 00:56:32.000000000 +0200 @@ -223,124 +223,7 @@ }
-int cs_response(search_key_cs *s) { - - void *p; - int count = 0; - int identifier = RESPONSE_CLIENT_STATE; - int arg_len = API_HEADER_LEN + sizeof(search_key_cs); - char *api_msg; //identifier + size + nslp_id - unsigned short nslp_id = 0xaaa;// remove this later!! - api_msg = (char *)calloc(1, arg_len); - p=api_msg; - - memcpy(p, &identifier, sizeof(int)); - p=(char *)p+sizeof(int); - - memcpy(p, &arg_len, sizeof(int)); - p=(char *)p+sizeof(int); - - memcpy(p, &nslp_id, sizeof(short)); - p=(char *)p+sizeof(short); - - memcpy(p, s, sizeof(search_key_cs)); - p=NULL; - - - if((count = send(gimps->sd_unix_socket, api_msg, arg_len, 0))<=0) { - if((count == 0) || (errno == ECONNRESET)) { - fprintf(stderr, "*** Unix Socket: Connection reset by peer ***\n"); - free(api_msg); - close(gimps->sd_unix_socket); - return count; - } else { - perror("NslpApi::cs_response_client_state(): send"); - free(api_msg); - return count; - } - } - - free(api_msg); - return 0; -} - - -void buf2getClientState(search_key *s) { - - search_key_cs r; - r.client_state = NULL; - -#if API_DEBUG - struct in_addr sip, dip; - fprintf(stderr, "\n*** API-Call get_client_state() ***\n\n"); - fprintf(stderr, "sid : "); - for(int i=0;i<SID_SIZE;i++) { - fprintf(stderr, "0x%02x ", s->sid[i]); - } - fprintf(stderr, "\n"); - fprintf(stderr, "mri->msgRoutingMethod : 0x%04x\n", s->mri.msgRoutingMethod); - fprintf(stderr, "mri->s : %d\n", s->mri.s); - fprintf(stderr, "mri->f : %d\n", s->mri.f); - fprintf(stderr, "mri->t : %d\n", s->mri.t); - fprintf(stderr, "mri->p : %d\n", s->mri.p); - fprintf(stderr, "mri->ipVersion : 0x%02x\n", s->mri.ipVersion); - fprintf(stderr, "mri->reserved : 0x%02x\n", s->mri.reserved); - fprintf(stderr, "mri->d : %d\n", s->mri.d); - fprintf(stderr, "mri->b : %d\n", s->mri.b); - fprintf(stderr, "mri->a : %d\n", s->mri.a); - sip.s_addr = s->mri.srcAddr; - dip.s_addr = s->mri.destAddr; - fprintf(stderr, "mri->srcAddr : %s\n", inet_ntoa(sip)); - fprintf(stderr, "mri->destAddr : %s\n", inet_ntoa(dip)); - fprintf(stderr, "mri->srcPrefix : 0x%02x\n", s->mri.srcPrefix); - fprintf(stderr, "mri->destPrefix : 0x%02x\n", s->mri.destPrefix); - fprintf(stderr, "mri->protocol : 0x%02x\n", s->mri.protocol); - fprintf(stderr, "mri->traffic_class : 0x%02x\n", s->mri.traffic_class); -#endif - - memcpy(&r, s, sizeof(search_key)); - //r->client_state = gimps->get_client_state(s->sid, s->mri); - cs_response(&r); - -} - - -void buf2delClientState(search_key *s) { - - -#if API_DEBUG - struct in_addr sip, dip; - fprintf(stderr, "\n*** API-Call del_client_state() ***\n\n"); - fprintf(stderr, "sid : "); - for(int i=0;i<SID_SIZE;i++) { - fprintf(stderr, "0x%02x ", s->sid[i]); - } - fprintf(stderr, "\n"); - fprintf(stderr, "mri->msgRoutingMethod : 0x%04x\n", s->mri.msgRoutingMethod); - fprintf(stderr, "mri->s : %d\n", s->mri.s); - fprintf(stderr, "mri->f : %d\n", s->mri.f); - fprintf(stderr, "mri->t : %d\n", s->mri.t); - fprintf(stderr, "mri->p : %d\n", s->mri.p); - fprintf(stderr, "mri->ipVersion : 0x%02x\n", s->mri.ipVersion); - fprintf(stderr, "mri->reserved : 0x%02x\n", s->mri.reserved); - fprintf(stderr, "mri->d : %d\n", s->mri.d); - fprintf(stderr, "mri->b : %d\n", s->mri.b); - fprintf(stderr, "mri->a : %d\n", s->mri.a); - sip.s_addr = s->mri.srcAddr; - dip.s_addr = s->mri.destAddr; - fprintf(stderr, "mri->srcAddr : %s\n", inet_ntoa(sip)); - fprintf(stderr, "mri->destAddr : %s\n", inet_ntoa(dip)); - fprintf(stderr, "mri->srcPrefix : 0x%02x\n", s->mri.srcPrefix); - fprintf(stderr, "mri->destPrefix : 0x%02x\n", s->mri.destPrefix); - fprintf(stderr, "mri->protocol : 0x%02x\n", s->mri.protocol); - fprintf(stderr, "mri->traffic_class : 0x%02x\n", s->mri.traffic_class); -#endif - - //gimps->del_client_state(s->sid, s->mri); -} - - -void ParseApiMsg(char *api_header) { +void ParseApiMsg(int sock, char *api_header) {
unsigned int identifier = 0; unsigned short nslp_id = 0; @@ -361,10 +244,10 @@ if(size) {
buffer = (char *) calloc(1, size); - if((count = recv(gimps->sd_unix_socket, buffer, size, 0)) <= 0) { + if((count = recv(sock, buffer, size, 0)) <= 0) { if((count == 0) || (errno == ECONNRESET)) { fprintf(stderr, "*** Unix Socket: Connection reset by peer ***\n"); - gimps->close_socket(gimps->sd_unix_socket); + gimps->close_socket(sock); return; } else { perror("ParseApiMsg(): Unix Socket recv"); @@ -385,12 +268,8 @@ case TEST_MSG_STATUS : {buf2TestMsgStatus (buffer); break;} case TEST_NWN : {buf2TestNWN (buffer); break;}
- case SET_CLIENT_STATE : {buf2setClientState ((search_key_cs *)buffer); break;} - case QUERY_CLIENT_STATE : {buf2getClientState ((search_key *)buffer); break;} - case DEL_CLIENT_STATE : {buf2delClientState ((search_key *)buffer); break;} - - case REGISTER_NSLPID : {gimps->registerNslpApp(gimps->sd_unix_socket, nslp_id); break;} - case UNREGISTER_NSLPID : {gimps->unregisterNslpApp(gimps->sd_unix_socket, nslp_id); break;} + case REGISTER_NSLPID : {gimps->registerNslpApp(sock, nslp_id); break;} + case UNREGISTER_NSLPID : {gimps->unregisterNslpApp(sock, nslp_id); break;} default : fprintf(stderr, "Api Call: Unknown identifier: %d\n", identifier);
} diff -Naur nsis_0.1.1.bak/nslp_api/nslp_api.cpp nsis_0.1.1/nslp_api/nslp_api.cpp --- nsis_0.1.1.bak/nslp_api/nslp_api.cpp 2005-08-03 11:51:17.000000000 +0200 +++ nsis_0.1.1/nslp_api/nslp_api.cpp 2005-08-21 00:58:45.000000000 +0200 @@ -173,7 +173,14 @@ void *p; int count = 0; api_recv_msg s; + Gimps_Nslp_Registry_Entry_t *reEntry = new Gimps_Nslp_Registry_Entry_t;
+ if((reEntry = gimps->getSockForNslpApp(nslp_id)) == NULL) { + + fprintf(stderr, "RecvMessage(): NSLP-ID not found.\n"); + + } + s.nd_size = nd_size; s.nslp_id = nslp_id; memcpy(&s.sid, sid, SID_SIZE); @@ -251,11 +258,11 @@
p=NULL;
- if((count = send(gimps->sd_unix_socket, api_msg, arg_len, 0))<=0) { + if((count = send(reEntry->sock, api_msg, arg_len, 0))<=0) { if((count == 0) || (errno == ECONNRESET)) { fprintf(stderr, "*** Unix Socket: Connection reset by peer ***\n"); free(api_msg); - close(gimps->sd_unix_socket); + gimps->close_socket(reEntry->sock); return; } else { perror("RecvMessage(): send"); @@ -264,6 +271,7 @@ } }
+ //delete reEntry; // does not work free(api_msg); return; } @@ -276,7 +284,7 @@ char *api_msg; int identifier = MESSAGE_STATUS; void *p; - int count = 0; + //int count = 0; api_msg_status s;
s.nslp_message_handle = nslp_message_handle; @@ -315,7 +323,7 @@ if(nslp_message_handle!=NULL) memcpy(p, nslp_message_handle, sizeof(nslp_message_handle));
p=NULL; - +/* if((count = send(gimps->sd_unix_socket, api_msg, arg_len, 0))<=0) { if((count == 0) || (errno == ECONNRESET)) { fprintf(stderr, "*** Unix Socket: Connection reset by peer ***\n"); @@ -328,7 +336,7 @@ return; } } - +*/ free(api_msg); return; } @@ -340,7 +348,7 @@ char *api_msg; int identifier = NW_NOTIFICATION; void *p; - int count = 0; + //int count = 0; api_nw_notification s;
s.nwnt = network_notification_type; @@ -393,7 +401,7 @@ memcpy(p, mri, sizeof(msg_routing_info_t));
p=NULL; - +/* if((count = send(gimps->sd_unix_socket, api_msg, arg_len, 0))<=0) { if((count == 0) || (errno == ECONNRESET)) { fprintf(stderr, "*** Unix Socket: Connection reset by peer ***\n"); @@ -406,7 +414,7 @@ return; } } - +*/ free(api_msg); return; } diff -Naur nsis_0.1.1.bak/nslp_api/nslp_api.h nsis_0.1.1/nslp_api/nslp_api.h --- nsis_0.1.1.bak/nslp_api/nslp_api.h 2005-08-03 11:51:17.000000000 +0200 +++ nsis_0.1.1/nslp_api/nslp_api.h 2005-08-21 00:47:11.000000000 +0200 @@ -56,6 +56,6 @@ void SetStateLifetime(msg_routing_info_t *mri, bool direction, unsigned char state_lifetime, Gimps *gimps); void InvalidateRoutingState(unsigned short nslp_id, msg_routing_info_t *mri, bool direction, bool urgency, Gimps *gimps);
-void ParseApiMsg(char *api_header); +void ParseApiMsg(int sock, char *api_header);
#endif // NSLP_API_H diff -Naur nsis_0.1.1.bak/socket_events.cpp nsis_0.1.1/socket_events.cpp --- nsis_0.1.1.bak/socket_events.cpp 2005-08-03 11:51:17.000000000 +0200 +++ nsis_0.1.1/socket_events.cpp 2005-08-21 00:49:13.000000000 +0200 @@ -280,8 +280,6 @@ } #endif gimps->register_unix_sd(nsd); - gimps->sd_unix_socket = nsd; - gimps->addPendingNslpApp(nsd); }
@@ -294,10 +292,10 @@ bzero(api_header, API_HEADER_LEN);
- if((count = recv(gimps->sd_unix_socket/*sock*/, api_header, API_HEADER_LEN, 0)) <= 0) { + if((count = recv(sock, api_header, API_HEADER_LEN, 0)) <= 0) { if((count == 0) || (errno == ECONNRESET)) { fprintf(stderr, "*** Unix Socket: Connection reset by peer ***\n"); - gimps->close_socket(gimps->sd_unix_socket); + gimps->close_socket(sock); return; } else { perror("Unix Socket recv"); @@ -305,7 +303,7 @@ } }
- ParseApiMsg(api_header); + ParseApiMsg(sock, api_header); //TODO: finish registry }