Bladeren bron

cmRtNet.h/c: Many changes. Completed testing of cmRtNetTest().

master
kpl 11 jaren geleden
bovenliggende
commit
63bba3ffa7
2 gewijzigde bestanden met toevoegingen van 299 en 203 verwijderingen
  1. 230
    126
      cmRtNet.c
  2. 69
    77
      cmRtNet.h

+ 230
- 126
cmRtNet.c Bestand weergeven

9
 #include "cmTime.h"
9
 #include "cmTime.h"
10
 #include "cmRtSysMsg.h"
10
 #include "cmRtSysMsg.h"
11
 
11
 
12
+// flags for cmRtNetNode_t.flags;
12
 enum
13
 enum
13
 {
14
 {
14
   kLocalNodeNetFl = 0x01,
15
   kLocalNodeNetFl = 0x01,
15
   kValidNodeNetFl = 0x02
16
   kValidNodeNetFl = 0x02
16
 };
17
 };
17
 
18
 
19
+// flags for cmRtNet_t.flags
20
+enum
21
+{
22
+  kReportSyncNetFl = 0x01
23
+};
24
+
18
 typedef enum
25
 typedef enum
19
 {
26
 {
20
-  kHelloSelNetId,
21
-  kNodeSelNetId,
22
-  kEndpointSelNetId,
23
-  kEndpointAckSelNetId,
24
-  kDoneSelNetId,
27
+  kHelloSelNetId,         // broadcast msg (label=node label, id=endpt cnt)
28
+  kNodeSelNetId,          // define remote node  (label=remote node label, id=endpt cnt)
29
+  kEndpointSelNetId,      // define remote endpt (label=remote endpt label, id=endpt id)
30
+  kDoneSelNetId,          // declare all endpts sent
31
+  kInvalidSelNetId
25
 } cmRtNetSelId_t;
32
 } cmRtNetSelId_t;
26
 
33
 
34
+struct cmRtNetNode_str;
35
+
27
 typedef struct cmRtNetEnd_str
36
 typedef struct cmRtNetEnd_str
28
 {
37
 {
29
-  cmChar_t*              label;
30
-  unsigned               id;
31
-  struct cmRtNetEnd_str* link;
38
+  cmChar_t*               label;
39
+  unsigned                id;
40
+  struct cmRtNetNode_str* np;   // Owner node.
41
+  struct cmRtNetEnd_str*  link;
32
 } cmRtNetEnd_t;
42
 } cmRtNetEnd_t;
33
 
43
 
34
 
44
 
35
 typedef struct cmRtNetNode_str
45
 typedef struct cmRtNetNode_str
36
 {
46
 {
37
-  cmChar_t*               label;
38
-  struct sockaddr_in      sockaddr;
39
-  cmChar_t*               addr;
40
-  cmUdpPort_t             port;
41
-  unsigned                flags;
47
+  cmChar_t*               label;          // Node label.
48
+  struct sockaddr_in      sockaddr;       // Socket address
49
+  cmChar_t*               addr;           // IP Address (human readable)
50
+  cmUdpPort_t             port;           // Socket port
51
+  unsigned                flags;          // See kXXXNodeNetFl flags above.
42
   unsigned                endPtIdx;       // tracks the next endpoint to send during sync-mode
52
   unsigned                endPtIdx;       // tracks the next endpoint to send during sync-mode
43
   unsigned                endPtCnt;       // local-node=actual cnt of endpt's remote-node:expected cnt of endpt's
53
   unsigned                endPtCnt;       // local-node=actual cnt of endpt's remote-node:expected cnt of endpt's
44
-  cmTimeSpec_t            lastSendTime;
45
-  cmRtNetEnd_t*           ends;
54
+  cmTimeSpec_t            lastSendTime;   // Time of last message sent
55
+  cmRtNetEnd_t*           ends;           // End point list for this node
46
   struct cmRtNetNode_str* link;
56
   struct cmRtNetNode_str* link;
47
 } cmRtNetNode_t;
57
 } cmRtNetNode_t;
48
 
58
 
49
 typedef struct
59
 typedef struct
50
 {
60
 {
51
-  cmErr_t         err;
52
-  cmUdpH_t        udpH;
53
-  cmUdpCallback_t cbFunc;
54
-  void*           cbArg;
55
-  cmRtNetNode_t*  nodes;
56
-  cmRtNetNode_t*  localNode;
57
-  unsigned        udpRecvBufByteCnt;
58
-  unsigned        udpTimeOutMs;
59
-  unsigned        interSyncSendTimeMs;
61
+  cmErr_t         err;                   // Error state object
62
+  unsigned        flags;                 // See kXXXNetFl above.
63
+  cmUdpH_t        udpH;                  // UDP port handle
64
+  cmUdpCallback_t cbFunc;                // Client callback to receive incoming messages from network.
65
+  void*           cbArg;                 //
66
+  cmRtNetNode_t*  nodes;                 // Node list.
67
+  cmRtNetNode_t*  localNode;             // Pointer to local node (which is also in node list)
68
+  unsigned        udpRecvBufByteCnt;     // UDP port receive buffer size.
69
+  unsigned        udpTimeOutMs;          // UDP time-out period
70
+  cmChar_t*       bcastAddr;             // Network broadcast address
60
 } cmRtNet_t;
71
 } cmRtNet_t;
61
 
72
 
62
-
73
+// Network synchronization message format
63
 typedef struct
74
 typedef struct
64
 {
75
 {
65
-  cmRtSysMsgHdr_t hdr;
66
-  cmRtNetSelId_t  selId;
76
+  cmRtSysMsgHdr_t hdr;    // standard cmRtSys msg  header 
77
+  cmRtNetSelId_t  selId;  // message selector id (See kXXXSelNetId above)
67
   const cmChar_t* label;  // node     or endpoint label
78
   const cmChar_t* label;  // node     or endpoint label
68
   unsigned        id;     // endptCnt or endpoint id
79
   unsigned        id;     // endptCnt or endpoint id
69
 } cmRtNetSyncMsg_t;
80
 } cmRtNetSyncMsg_t;
70
 
81
 
71
-cmRtNetH_t cmRtNetNullHandle = cmSTATIC_NULL_HANDLE;
82
+cmRtNetH_t      cmRtNetNullHandle      = cmSTATIC_NULL_HANDLE;
83
+cmRtNetEndptH_t cmRtNetEndptNullHandle = cmSTATIC_NULL_HANDLE;
72
 
84
 
73
 cmRtNet_t* _cmRtNetHandleToPtr( cmRtNetH_t h )
85
 cmRtNet_t* _cmRtNetHandleToPtr( cmRtNetH_t h )
74
 {
86
 {
79
 
91
 
80
 void _cmRtNetVRpt( cmRtNet_t* p, const cmChar_t* fmt, va_list vl )
92
 void _cmRtNetVRpt( cmRtNet_t* p, const cmChar_t* fmt, va_list vl )
81
 {
93
 {
82
-  cmRptVPrintf(p->err.rpt,fmt,vl);
94
+  if( cmIsFlag(p->flags,kReportSyncNetFl) )
95
+    cmRptVPrintf(p->err.rpt,fmt,vl);
83
 }
96
 }
84
 
97
 
85
 void _cmRtNetRpt( cmRtNet_t* p, const cmChar_t* fmt, ... )
98
 void _cmRtNetRpt( cmRtNet_t* p, const cmChar_t* fmt, ... )
143
 
156
 
144
     np = nnp;
157
     np = nnp;
145
   }
158
   }
146
-  p->nodes = NULL;
159
+  p->nodes     = NULL;
147
   p->localNode = NULL;
160
   p->localNode = NULL;
148
 }
161
 }
149
 
162
 
188
   
201
   
189
   np           = cmMemAllocZ(cmRtNetNode_t,1);
202
   np           = cmMemAllocZ(cmRtNetNode_t,1);
190
   np->label    = cmMemAllocStr(label);
203
   np->label    = cmMemAllocStr(label);
191
-  np->sockaddr = *saddr;
204
+
205
+  if( saddr != NULL )
206
+    np->sockaddr = *saddr;
207
+
192
   np->addr     = addr==NULL ? NULL : cmMemAllocStr(addr);
208
   np->addr     = addr==NULL ? NULL : cmMemAllocStr(addr);
193
   np->port     = port;
209
   np->port     = port;
194
   np->flags    = flags;
210
   np->flags    = flags;
235
 
251
 
236
   ep->label = cmMemAllocStr(endPtLabel);
252
   ep->label = cmMemAllocStr(endPtLabel);
237
   ep->id    = endPtId;
253
   ep->id    = endPtId;
238
-  ep->link      = np->ends;
239
-  np->ends      = ep;
254
+  ep->np    = np;
255
+  ep->link  = np->ends;
256
+  np->ends  = ep;
240
 
257
 
241
   return rc;
258
   return rc;
242
 }
259
 }
243
 
260
 
261
+unsigned _cmRtNetNodeEndpointCount( cmRtNetNode_t* np )
262
+{
263
+  cmRtNetEnd_t* ep = np->ends;
264
+  unsigned      n  = 0;
265
+  for(; ep!=NULL; ep=ep->link)
266
+    ++n;
267
+  return n;
268
+}
269
+
244
 unsigned _cmRtNetSyncMsgSerialByteCount( const cmRtNetSyncMsg_t* m )
270
 unsigned _cmRtNetSyncMsgSerialByteCount( const cmRtNetSyncMsg_t* m )
245
 { return sizeof(cmRtNetSyncMsg_t) + (m->label==NULL ? 1 : strlen(m->label) + 1); }
271
 { return sizeof(cmRtNetSyncMsg_t) + (m->label==NULL ? 1 : strlen(m->label) + 1); }
246
 
272
 
287
   if((rc = _cmRtNetSerializeSyncMsg(p,&m,buf,n)) != kOkNetRC )
313
   if((rc = _cmRtNetSerializeSyncMsg(p,&m,buf,n)) != kOkNetRC )
288
     return rc;
314
     return rc;
289
 
315
 
290
- 
291
   // send the msg
316
   // send the msg
292
-  if( np==p->localNode )
293
-    udpRC = cmUdpSend2(p->udpH, buf, n, "255.255.255.255", np->port );
317
+  if( selId == kHelloSelNetId )
318
+    udpRC = cmUdpSend2(p->udpH, buf, n, p->bcastAddr, np->port );
294
   else
319
   else
295
     udpRC = cmUdpSendTo(p->udpH, buf, n, &np->sockaddr );
320
     udpRC = cmUdpSendTo(p->udpH, buf, n, &np->sockaddr );
296
 
321
 
317
 
342
 
318
   _cmRtNetReleaseNodes(p);
343
   _cmRtNetReleaseNodes(p);
319
 
344
 
345
+  cmMemFree(p->bcastAddr);
346
+
320
   cmMemFree(p);
347
   cmMemFree(p);
321
   return rc;
348
   return rc;
322
 }
349
 }
323
 
350
 
324
-
325
 cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg )
351
 cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg )
326
 {
352
 {
327
   cmRtNetRC_t rc;
353
   cmRtNetRC_t rc;
340
 
366
 
341
   p->udpTimeOutMs        = 50;
367
   p->udpTimeOutMs        = 50;
342
   p->udpRecvBufByteCnt   = 8192;
368
   p->udpRecvBufByteCnt   = 8192;
343
-  p->interSyncSendTimeMs = 10;
344
   p->cbFunc = cbFunc;
369
   p->cbFunc = cbFunc;
345
   p->cbArg  = cbArg;
370
   p->cbArg  = cbArg;
346
 
371
 
386
   return p->udpH;
411
   return p->udpH;
387
 }
412
 }
388
 
413
 
389
-cmRtNetRC_t  _cmRtNetSendEndpointReplyMsg( cmRtNet_t* p, cmRtNetNode_t* np )
414
+cmRtNetRC_t  _cmRtNetSendEndpointReplyMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRtNetSelId_t srcSelId )
390
 {
415
 {
391
   cmRtNetRC_t     rc = kOkNetRC;
416
   cmRtNetRC_t     rc = kOkNetRC;
392
   cmRtNetEnd_t*   ep;
417
   cmRtNetEnd_t*   ep;
398
   if( np == NULL )
423
   if( np == NULL )
399
     return cmErrMsg(&p->err,kNodeNotFoundNetRC,"The net node associated with an endpoint reply was not found.");
424
     return cmErrMsg(&p->err,kNodeNotFoundNetRC,"The net node associated with an endpoint reply was not found.");
400
 
425
 
401
-  // if all of the endpoints have been sent to this node ...
402
-  if((ep = _cmRtNetIndexToEndpoint(p,p->localNode,np->endPtIdx)) == NULL )
426
+  // if we got here by receiving a 'done' msg from the remote node ...
427
+  if( srcSelId == kDoneSelNetId )
403
   {
428
   {
404
-    if( np->endPtIdx == p->localNode->endPtCnt )
405
-    {
406
-      selId = kDoneSelNetId;
407
-      rptLabel = "done";
408
-    }
429
+    // ... then mark the remote node as having recieved all endpoints
430
+    unsigned n;
431
+    if((n = _cmRtNetNodeEndpointCount(np)) != np->endPtCnt )
432
+      rc = cmErrMsg(&p->err,kNodeEndCntErrNetRC,"The node '%s' expected %i endpoints but received %i.",cmStringNullGuard(np->label),np->endPtCnt,n);
409
     else
433
     else
410
-    {
411
-      selId = kEndpointAckSelNetId;
412
-      rptLabel = "ep ack";
413
-    }
414
-   
434
+      np->flags = cmSetFlag(np->flags,kValidNodeNetFl);
415
   }
435
   }
416
-  else
436
+
437
+  // attempt to get the next local endpoint to send ...
438
+  if((ep = _cmRtNetIndexToEndpoint(p,p->localNode,np->endPtIdx)) != NULL )
417
   {
439
   {
418
-    msgLabel = ep->label;
440
+    msgLabel = ep->label;  // ... send next local endpoint
419
     msgId    = ep->id;
441
     msgId    = ep->id;
420
   }
442
   }
443
+  else // .... all local endpoints have been sent
444
+  {
445
+    selId    = kInvalidSelNetId;  
446
+    rptLabel = "done";
421
 
447
 
422
-  // notify the remote node that all endpoints have been sent
423
-  if((rc = _cmRtNetSendSyncMsg(p,np,selId,msgLabel,msgId )) != kOkNetRC )
424
-    rc = cmErrMsg(&p->err,rc,"Send '%s' to %s:%s:%i failed.",rptLabel,cmStringNullGuard(np->label),cmStringNullGuard(np->addr),np->port);
425
-  else
426
-    _cmRtNetRpt(p,"Sent %s.\n",cmStringNullGuard(rptLabel));
448
+    // verify that no endpoints are available
449
+    if( np->endPtIdx < p->localNode->endPtCnt )
450
+      rc = cmErrMsg(&p->err,kSyncFailNetRC,"More endpoints are available to send but are not reachable.");
451
+    else
452
+    {
453
+      // if the remote node still has endpts to send then continue
454
+      // sending 'done' messages.
455
+      if( np->endPtIdx==p->localNode->endPtCnt || srcSelId != kDoneSelNetId )
456
+        selId = kDoneSelNetId;
457
+    }   
458
+  }
427
 
459
 
428
-  np->endPtIdx += 1;
460
+  // selId is set to kInvalidSelNetId when we encounter the (stop) criteria
461
+  if( selId != kInvalidSelNetId )
462
+  {
463
+    if((rc = _cmRtNetSendSyncMsg(p,np,selId,msgLabel,msgId )) != kOkNetRC )
464
+      rc = cmErrMsg(&p->err,rc,"Send '%s' to %s:%s:%i failed.",rptLabel,cmStringNullGuard(np->label),cmStringNullGuard(np->addr),np->port);
465
+    else
466
+      _cmRtNetRpt(p,"Sent %s.\n",cmStringNullGuard(rptLabel));
467
+
468
+    np->endPtIdx += 1;
469
+  }
429
 
470
 
430
   return rc;
471
   return rc;
431
-  
472
+}
473
+
474
+bool    _cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt )
475
+{
476
+  cmRtNetSyncMsg_t* m = (cmRtNetSyncMsg_t*)data;
477
+  return dataByteCnt >= sizeof(cmRtNetSyncMsg_t) && m->hdr.selId == kNetSyncSelRtId;
432
 }
478
 }
433
 
479
 
434
 // When the network message recieve function (See cmRtNetAlloc() 'cbFunc') 
480
 // When the network message recieve function (See cmRtNetAlloc() 'cbFunc') 
438
 cmRtNetRC_t  _cmRtNetSyncModeRecv( cmRtNet_t* p, const char* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr )
484
 cmRtNetRC_t  _cmRtNetSyncModeRecv( cmRtNet_t* p, const char* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr )
439
 {
485
 {
440
   cmRtNetRC_t      rc = kOkNetRC;
486
   cmRtNetRC_t      rc = kOkNetRC;
441
-  cmRtNetSyncMsg_t m;
487
+  cmRtNetSyncMsg_t  m;
442
   m.label = NULL;
488
   m.label = NULL;
443
 
489
 
444
-  assert( cmRtNetIsSyncModeMsg(data,dataByteCnt));
490
+  assert( _cmRtNetIsSyncModeMsg(data,dataByteCnt));
445
   
491
   
446
   if( _cmRtNetDeserializeSyncMsg(data,dataByteCnt,&m) != kOkNetRC )
492
   if( _cmRtNetDeserializeSyncMsg(data,dataByteCnt,&m) != kOkNetRC )
447
   {
493
   {
449
     goto errLabel;
495
     goto errLabel;
450
   }
496
   }
451
 
497
 
498
+  _cmRtNetRpt(p,"recv from:%s\n",cmUdpAddrToString(p->udpH, fromAddr ));
499
+
500
+
452
   assert( m.hdr.selId == kNetSyncSelRtId );
501
   assert( m.hdr.selId == kNetSyncSelRtId );
453
 
502
 
454
   // attempt to locate the remote node which sent the msg
503
   // attempt to locate the remote node which sent the msg
455
   cmRtNetNode_t* np = _cmRtNetFindNodeFromSockAddr(p,fromAddr);
504
   cmRtNetNode_t* np = _cmRtNetFindNodeFromSockAddr(p,fromAddr);
456
 
505
 
506
+
457
   switch( m.selId )
507
   switch( m.selId )
458
   {
508
   {
459
     case kHelloSelNetId:    
509
     case kHelloSelNetId:    
510
+      // if this is a response to a broadcast from the local node then ignore it
511
+      if(m.label!=NULL && p->localNode->label!=NULL && (np = _cmRtNetFindNode(p,m.label)) != NULL && strcmp(p->localNode->label,m.label)==0 )
512
+      {
513
+        const cmChar_t* fromAddrStr  = cmUdpAddrToString(p->udpH,fromAddr);
514
+        const cmChar_t* localAddrStr = cmUdpAddrToString(p->udpH,cmUdpLocalAddr(p->udpH));
515
+
516
+        if( fromAddrStr!=NULL && localAddrStr!=NULL && strcmp(fromAddrStr,localAddrStr)==0)
517
+          cmErrMsg(&p->err,kDuplLocalNetRC,"The node label '%s' appears to be duplicated at address %s and locally.",cmStringNullGuard(m.label),fromAddrStr);
518
+
519
+        np->sockaddr = *fromAddr;
520
+        goto errLabel;
521
+      } 
522
+      // fall through
523
+
460
     case kNodeSelNetId: 
524
     case kNodeSelNetId: 
461
       {
525
       {
462
         // if the node already exists ...
526
         // if the node already exists ...
472
         if(( rc = _cmRtNetCreateNode(p,m.label,NULL,0,fromAddr,0,m.id)) != kOkNetRC )
536
         if(( rc = _cmRtNetCreateNode(p,m.label,NULL,0,fromAddr,0,m.id)) != kOkNetRC )
473
           goto errLabel;        
537
           goto errLabel;        
474
 
538
 
539
+        np = p->nodes; // newest node is always the first node
540
+
475
         // send response
541
         // send response
476
         switch( m.selId )
542
         switch( m.selId )
477
         {
543
         {
478
           case kHelloSelNetId:
544
           case kHelloSelNetId:
479
             _cmRtNetRpt(p,"rcv hello\n"); // reply with local node
545
             _cmRtNetRpt(p,"rcv hello\n"); // reply with local node
480
-            rc = _cmRtNetSendSyncMsg( p, np, kNodeSelNetId, NULL, p->localNode->endPtCnt );
546
+            rc = _cmRtNetSendSyncMsg( p, np, kNodeSelNetId, p->localNode->label, p->localNode->endPtCnt );
481
             break;
547
             break;
482
 
548
 
483
           case kNodeSelNetId:
549
           case kNodeSelNetId:
484
             _cmRtNetRpt(p,"rcv node\n");
550
             _cmRtNetRpt(p,"rcv node\n");
485
-            _cmRtNetSendEndpointReplyMsg( p, np ); // reply with first endpoint
551
+            _cmRtNetSendEndpointReplyMsg( p, np, m.selId ); // reply with first endpoint
486
             break;
552
             break;
487
 
553
 
488
           default:
554
           default:
492
       }
558
       }
493
       break;
559
       break;
494
 
560
 
495
-    
496
-    case kEndpointAckSelNetId:
497
     case kDoneSelNetId:
561
     case kDoneSelNetId:
498
-      rc = _cmRtNetSendEndpointReplyMsg(p,np);
562
+      //case kEndpointAckSelNetId:
563
+      rc = _cmRtNetSendEndpointReplyMsg(p,np,m.selId);
499
       break;
564
       break;
500
 
565
 
501
     case kEndpointSelNetId: 
566
     case kEndpointSelNetId: 
502
       {
567
       {
503
         cmRtNetEnd_t* ep;
568
         cmRtNetEnd_t* ep;
504
 
569
 
505
-
506
         // verify the remote node exists.
570
         // verify the remote node exists.
507
         if( np == NULL )
571
         if( np == NULL )
508
         {
572
         {
521
         }
585
         }
522
 
586
 
523
         // reply with a local endpoint or 'done' msg
587
         // reply with a local endpoint or 'done' msg
524
-        rc = _cmRtNetSendEndpointReplyMsg( p, np );
588
+        rc = _cmRtNetSendEndpointReplyMsg( p, np, m.selId );
525
       }
589
       }
526
       break;
590
       break;
527
 
591
 
540
 {
604
 {
541
   cmRtNet_t* p = (cmRtNet_t*)cbArg;
605
   cmRtNet_t* p = (cmRtNet_t*)cbArg;
542
   
606
   
543
-  if( cmRtNetIsSyncModeMsg(data,dataByteCnt))
607
+  if( _cmRtNetIsSyncModeMsg(data,dataByteCnt))
544
     _cmRtNetSyncModeRecv(p,data,dataByteCnt,fromAddr);
608
     _cmRtNetSyncModeRecv(p,data,dataByteCnt,fromAddr);
545
   else
609
   else
546
     p->cbFunc(p->cbArg,data,dataByteCnt,fromAddr);
610
     p->cbFunc(p->cbArg,data,dataByteCnt,fromAddr);
547
   
611
   
548
 }
612
 }
549
 
613
 
550
-
551
-
552
-cmRtNetRC_t cmRtNetRegisterLocalNode( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t port )
614
+cmRtNetRC_t cmRtNetInitialize( cmRtNetH_t h, const cmChar_t* bcastAddr, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t port )
553
 {
615
 {
554
   cmRtNet_t*  p = _cmRtNetHandleToPtr(h);
616
   cmRtNet_t*  p = _cmRtNetHandleToPtr(h);
555
   cmRtNetRC_t rc;
617
   cmRtNetRC_t rc;
556
-  struct sockaddr_in sockaddr;
557
 
618
 
558
   // release the local node
619
   // release the local node
559
-  if( p->localNode != NULL )
560
-  {    
561
-    _cmRtNetReleaseNode(p,p->localNode);
562
-    p->localNode = NULL;
563
-  }
620
+  if((rc = cmRtNetFinalize(h)) != kOkNetRC )
621
+    goto errLabel;
564
 
622
 
565
   // if this is the local node then initialze the local socket
623
   // if this is the local node then initialze the local socket
566
   if( cmUdpInit(p->udpH,port,kNonBlockingUdpFl | kBroadcastUdpFl,_cmRtNetRecv,p,NULL,0,p->udpRecvBufByteCnt,p->udpTimeOutMs) != kOkUdpRC )
624
   if( cmUdpInit(p->udpH,port,kNonBlockingUdpFl | kBroadcastUdpFl,_cmRtNetRecv,p,NULL,0,p->udpRecvBufByteCnt,p->udpTimeOutMs) != kOkUdpRC )
569
     goto errLabel;
627
     goto errLabel;
570
   }
628
   }
571
 
629
 
572
-  // get the socket address
573
-  if( cmUdpInitAddr(p->udpH, ipAddr, port, &sockaddr ) != kOkUdpRC )
574
-  {
575
-    rc = cmErrMsg(&p->err,kUdpPortFailNetRC,"IP::port to socket address conversion failed.");
576
-    goto errLabel;
577
-  }
578
-
579
   // create the local node
630
   // create the local node
580
-  if((rc = _cmRtNetCreateNode(p,nodeLabel, ipAddr, port, &sockaddr, kLocalNodeNetFl, 0)) != kOkNetRC )
631
+  if((rc = _cmRtNetCreateNode(p,nodeLabel, ipAddr, port, NULL, kLocalNodeNetFl, 0)) != kOkNetRC )
581
     goto errLabel;
632
     goto errLabel;
582
 
633
 
583
   // the last created node is always the first node on the list
634
   // the last created node is always the first node on the list
584
   p->localNode = p->nodes;
635
   p->localNode = p->nodes;
636
+  p->bcastAddr = cmMemResizeStr(p->bcastAddr,bcastAddr);
585
 
637
 
586
   // begin listening on the local port
638
   // begin listening on the local port
587
   if( cmUdpEnableListen(p->udpH, true ) != kOkUdpRC )
639
   if( cmUdpEnableListen(p->udpH, true ) != kOkUdpRC )
609
   return rc;
661
   return rc;
610
 }
662
 }
611
 
663
 
612
-cmRtNetRC_t cmRtNetClearAll( cmRtNetH_t h )
664
+cmRtNetRC_t cmRtNetFinalize( cmRtNetH_t h )
613
 {
665
 {
614
   cmRtNet_t* p = _cmRtNetHandleToPtr(h);
666
   cmRtNet_t* p = _cmRtNetHandleToPtr(h);
615
   _cmRtNetReleaseNodes(p);
667
   _cmRtNetReleaseNodes(p);
668
+  
616
   return kOkNetRC;
669
   return kOkNetRC;
617
 }
670
 }
618
 
671
 
619
-cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h )
672
+cmRtNetRC_t cmRtNetDoSync( cmRtNetH_t h )
620
 {
673
 {
621
   cmRtNet_t* p = _cmRtNetHandleToPtr(h);
674
   cmRtNet_t* p = _cmRtNetHandleToPtr(h);
622
 
675
 
623
   // broadcast 'node' msg
676
   // broadcast 'node' msg
624
-  return _cmRtNetSendSyncMsg( p, p->localNode, kHelloSelNetId, NULL, p->localNode->endPtCnt );
677
+  return _cmRtNetSendSyncMsg( p, p->localNode, kHelloSelNetId, p->localNode->label, p->localNode->endPtCnt );
625
 }
678
 }
626
 
679
 
627
-
628
-
629
 cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h )
680
 cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h )
630
 {
681
 {
631
   cmRtNetRC_t rc = kOkNetRC;
682
   cmRtNetRC_t rc = kOkNetRC;
640
   return rc;
691
   return rc;
641
 }
692
 }
642
 
693
 
643
-bool    cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt )
694
+cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp )
644
 {
695
 {
645
-  cmRtNetSyncMsg_t* m = (cmRtNetSyncMsg_t*)data;
646
-  return dataByteCnt >= sizeof(cmRtNetSyncMsg_t) && m->hdr.selId == kNetSyncSelRtId;
696
+  cmRtNetRC_t     rc = kOkNetRC;
697
+  cmRtNet_t*      p  = _cmRtNetHandleToPtr(h);
698
+  cmRtNetNode_t* np;
699
+  cmRtNetEnd_t*  ep;
700
+
701
+  if(( np = _cmRtNetFindNode(p,nodeLabel)) == NULL )
702
+    return cmErrMsg(&p->err,kNodeNotFoundNetRC,"The node '%s' was not found.",cmStringNullGuard(nodeLabel));
703
+
704
+
705
+  if(( ep = _cmRtNetFindNodeEnd(np, endptLabel )) == NULL )
706
+    return cmErrMsg(&p->err,kEndNotFoundNetRC,"The endpoint '%s' on '%s' on node was not found.",cmStringNullGuard(endptLabel),cmStringNullGuard(nodeLabel));
707
+
708
+  hp->h = ep;
709
+
710
+  return rc;
647
 }
711
 }
648
 
712
 
713
+cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt )
714
+{
715
+  cmRtNetRC_t     rc = kOkNetRC;
716
+  cmRtNet_t*      p  = _cmRtNetHandleToPtr(h);
717
+  cmRtNetEnd_t*   ep = (cmRtNetEnd_t*)epH.h;
718
+  
719
+  assert( ep != NULL );
720
+  
721
+  unsigned dN = sizeof(unsigned) + msgByteCnt; 
722
+  char data[ dN ];
723
+  unsigned *hdr = (unsigned*)data;
724
+  hdr[0] = ep->id;
725
+  memcpy(hdr+1,msg,msgByteCnt);
726
+  
727
+  if( cmUdpSendTo(p->udpH, data, dN, &ep->np->sockaddr ) != kOkUdpRC )
728
+    return cmErrMsg(&p->err,kUdpPortFailNetRC,"Send to node:%s endpt:%s failed.\n",cmStringNullGuard(ep->np->label),cmStringNullGuard(ep->label));
729
+
730
+  return rc;
731
+}
649
 
732
 
650
-unsigned  cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel )
733
+cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt )
651
 {
734
 {
652
-  //cmRtNet_t* p = _cmRtNetHandleToPtr(h);
653
-  return cmInvalidIdx;
654
-}  
735
+  cmRtNetRC_t     rc  = kOkNetRC;
736
+  cmRtNetEndptH_t epH = cmRtNetEndptNullHandle;
737
+
738
+  if((rc = cmRtNetEndpointHandle(h,nodeLabel,endptLabel,&epH)) != kOkNetRC )
739
+    return rc;
740
+
741
+  return cmRtNetSend(h,epH,msg,msgByteCnt);
742
+}
655
 
743
 
656
-cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, unsigned endPointIndex, const void* msg, unsigned msgByteCnt )
744
+
745
+
746
+bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl )
657
 {
747
 {
658
-  cmRtNetRC_t rc = kOkNetRC;
659
-  //cmRtNet_t* p = _cmRtNetHandleToPtr(h);
660
-  return rc;
748
+  cmRtNet_t* p  = _cmRtNetHandleToPtr(h);
749
+  bool       fl =  cmIsFlag(p->flags,kReportSyncNetFl);
750
+  p->flags = cmEnaFlag(p->flags,kReportSyncNetFl,enableFl);
751
+  return fl;  
752
+}
753
+
754
+bool cmRtNetReportSyncIsEnabled( cmRtNetH_t h )
755
+{
756
+  cmRtNet_t* p = _cmRtNetHandleToPtr(h);
757
+  return cmIsFlag(p->flags,kReportSyncNetFl);
661
 }
758
 }
662
 
759
 
663
 void   cmRtNetReport( cmRtNetH_t h )
760
 void   cmRtNetReport( cmRtNetH_t h )
699
 typedef struct
796
 typedef struct
700
 {
797
 {
701
   cmThreadH_t thH;
798
   cmThreadH_t thH;
702
-  cmRtNetH_t netH;
799
+  cmRtNetH_t  netH;
800
+  unsigned    msgVal;
703
 } _cmRtNetTest_t;
801
 } _cmRtNetTest_t;
704
 
802
 
705
 void _cmRtNetTestRecv( void* cbArg, const char* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr )
803
 void _cmRtNetTestRecv( void* cbArg, const char* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr )
706
 {
804
 {
707
   //_cmRtNetTest_t* p = (_cmRtNetTest_t*)cbArg;
805
   //_cmRtNetTest_t* p = (_cmRtNetTest_t*)cbArg;
708
-
806
+  
807
+  unsigned* hdr = (unsigned*)data;
808
+  printf("%i %i\n",hdr[0],hdr[1]);
709
 
809
 
710
 }
810
 }
711
 
811
 
712
-
812
+             
713
 bool _cmRtNetTestThreadFunc(void* param)
813
 bool _cmRtNetTestThreadFunc(void* param)
714
 {
814
 {
715
   _cmRtNetTest_t* p = (_cmRtNetTest_t*)param;
815
   _cmRtNetTest_t* p = (_cmRtNetTest_t*)param;
728
 {
828
 {
729
   char            c;
829
   char            c;
730
   _cmRtNetTest_t  t;
830
   _cmRtNetTest_t  t;
731
-  const cmChar_t* hostNameStr;
732
   cmUdpPort_t     port = 5876;
831
   cmUdpPort_t     port = 5876;
733
   _cmRtNetTest_t* p    = &t;
832
   _cmRtNetTest_t* p    = &t;
734
   cmRtNetRC_t     rc   = kOkNetRC;
833
   cmRtNetRC_t     rc   = kOkNetRC;
834
+  const cmChar_t* localHostStr   = mstrFl  ? "master"    : "slave";
835
+  const cmChar_t* localEndpStr   = mstrFl  ? "master_ep" : "slave_ep";
836
+  const cmChar_t* remoteHostStr  = !mstrFl ? "master"    : "slave";
837
+  const cmChar_t* remoteEndpStr  = !mstrFl ? "master_ep" : "slave_ep";
838
+  const cmChar_t* bcastAddr      = "192.168.15.255";
839
+
735
   memset(&t,0,sizeof(t));
840
   memset(&t,0,sizeof(t));
736
 
841
 
737
   if( cmThreadCreate(&p->thH,_cmRtNetTestThreadFunc,p,&ctx->rpt) != kOkThRC )
842
   if( cmThreadCreate(&p->thH,_cmRtNetTestThreadFunc,p,&ctx->rpt) != kOkThRC )
740
   if((rc = cmRtNetAlloc(ctx,&p->netH,_cmRtNetTestRecv,p)) != kOkNetRC )
845
   if((rc = cmRtNetAlloc(ctx,&p->netH,_cmRtNetTestRecv,p)) != kOkNetRC )
741
     goto errLabel;
846
     goto errLabel;
742
 
847
 
743
-  hostNameStr = cmRtNetLocalHostName(p->netH);
744
-  if( hostNameStr == NULL )
745
-    hostNameStr = "<no-host-name>";
848
+  cmRtNetReportSyncEnable(p->netH,true); // enable sync. protocol reporting
746
 
849
 
747
-  if((rc = cmRtNetRegisterLocalNode(p->netH, hostNameStr, NULL, port )) != kOkNetRC)
850
+  if((rc = cmRtNetInitialize(p->netH, bcastAddr, localHostStr, NULL, port )) != kOkNetRC)
748
     goto errLabel;
851
     goto errLabel;
749
 
852
 
750
-  if( mstrFl )
751
-  {
752
-    if((rc = cmRtNetRegisterEndPoint(p->netH,"thunk_ep0", 0 )) != kOkNetRC )
753
-      goto errLabel;
754
-
755
-    if(( rc = cmRtNetBeginSyncMode(p->netH)) != kOkNetRC )
756
-      goto errLabel;
757
-    
758
-  }
759
-  else
760
-  {
761
-    if((rc = cmRtNetRegisterEndPoint(p->netH,"whirl_ep0", 0 )) != kOkNetRC )
762
-      goto errLabel;
763
-  }
853
+  if((rc = cmRtNetRegisterEndPoint(p->netH,localEndpStr, 0 )) != kOkNetRC )
854
+    goto errLabel;
764
   
855
   
765
   if( cmThreadPause(p->thH,0) != kOkThRC )
856
   if( cmThreadPause(p->thH,0) != kOkThRC )
766
     goto errLabel;
857
     goto errLabel;
767
 
858
 
768
-  cmRptPrintf(&ctx->rpt,"%s q=quit\n", mstrFl ? "Master: " : "Slave: ");
859
+  cmRptPrintf(&ctx->rpt,"%s t=transmit s=sync r=report q=quit\n", localHostStr );
860
+
769
   while( (c=getchar()) != 'q' )
861
   while( (c=getchar()) != 'q' )
770
   {
862
   {
771
     switch(c)
863
     switch(c)
773
       case 'r':
865
       case 'r':
774
         cmRtNetReport(p->netH);
866
         cmRtNetReport(p->netH);
775
         break;
867
         break;
868
+
869
+      case 's':
870
+        cmRtNetDoSync(p->netH);
871
+        break;
872
+
873
+      case 't':
874
+        {
875
+          if( cmRtNetSendByLabels(p->netH, remoteHostStr, remoteEndpStr, &p->msgVal, sizeof(p->msgVal)) == kOkNetRC )
876
+            p->msgVal += 1;
877
+
878
+        }        
879
+        break;
776
     }
880
     }
777
     
881
     
778
   }
882
   }

+ 69
- 77
cmRtNet.h Bestand weergeven

11
     kUdpPortFailNetRC,
11
     kUdpPortFailNetRC,
12
     kInvalidLabelNetRC,
12
     kInvalidLabelNetRC,
13
     kDuplLabelNetRC,
13
     kDuplLabelNetRC,
14
-    kDuplLocalNetRC,
15
     kDuplEndNetRC,
14
     kDuplEndNetRC,
15
+    kDuplLocalNetRC,
16
     kThreadFailNetRC,
16
     kThreadFailNetRC,
17
     kBufToSmallNetRC,
17
     kBufToSmallNetRC,
18
     kNodeNotFoundNetRC,
18
     kNodeNotFoundNetRC,
19
-    kNodeStateErrNetRC,
20
-    kTimeOutErrNetRC,
19
+    kEndNotFoundNetRC,
21
     kLocalNodeNetRC,
20
     kLocalNodeNetRC,
21
+    kSyncFailNetRC,
22
+    kNodeEndCntErrNetRC
22
   };
23
   };
23
 
24
 
24
   typedef cmRC_t     cmRtNetRC_t;
25
   typedef cmRC_t     cmRtNetRC_t;
25
   typedef cmHandle_t cmRtNetH_t;
26
   typedef cmHandle_t cmRtNetH_t;
27
+  typedef cmHandle_t cmRtNetEndptH_t;
26
 
28
 
27
-
28
-  extern cmRtNetH_t cmRtNetNullHandle;
29
+  extern cmRtNetH_t      cmRtNetNullHandle;
30
+  extern cmRtNetEndptH_t cmRtNetEndptNullHandle;
29
 
31
 
30
   // 'cbFunc' will be called within the context of cmRtNetReceive() to receive
32
   // 'cbFunc' will be called within the context of cmRtNetReceive() to receive
31
   // incoming network messages.
33
   // incoming network messages.
34
 
36
 
35
   bool      cmRtNetIsValid( cmRtNetH_t h );
37
   bool      cmRtNetIsValid( cmRtNetH_t h );
36
 
38
 
39
+  // Get the local host name for this machine. This function
40
+  // is synonomous with gethostname().
37
   const cmChar_t* cmRtNetLocalHostName( cmRtNetH_t h );
41
   const cmChar_t* cmRtNetLocalHostName( cmRtNetH_t h );
38
 
42
 
39
-  // Create a network node.
40
-  // The 'nodeLabel' refers to a network device cfg. (see cmDevCfg).
41
-  // Set 'ipAddr' to NULL if this is the local node.
42
-  // During sync mode this node will attempt to sync with all
43
-  // nodes in the node list.
44
-  cmRtNetRC_t cmRtNetRegisterLocalNode( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
45
-
43
+  // Initialize the local network node.
44
+  // 'bcastAddr' is the network broadcast address (e.g. 192.168.15.255).
45
+  // 'nodeLabel' is the local network node label
46
+  // 'ipAddr' may be set to NULL to use any available IP address.
47
+  // 'ipPort' refers to the socket port (which may need to be made available 
48
+  // by the machine firewall cfg.)
49
+  cmRtNetRC_t cmRtNetInitialize( cmRtNetH_t h, const cmChar_t* bcastAddr, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
46
 
50
 
47
   // Register the local endpoints.
51
   // Register the local endpoints.
52
+  // Endpoints may only be registered once the network is initialized via
53
+  // cmRtNetInitialize().
48
   // Remote nodes will be able to send messages to these endpoints by
54
   // Remote nodes will be able to send messages to these endpoints by
49
   // referring to (nodeLabel/endPtLabel)
55
   // referring to (nodeLabel/endPtLabel)
50
   cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId );
56
   cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId );
51
 
57
 
52
   // Delete all nodes and endpoints.
58
   // Delete all nodes and endpoints.
53
-  cmRtNetRC_t cmRtNetClearAll( cmRtNetH_t h );
54
-
55
-
56
-  // Go into 'sync' node.
57
-  // When a node enters sync mode it systematically transmits all of it's 
58
-  // local endpoint information to each registered remote node.  Prior to 
59
-  // entering sync mode a node must therefore have been setup with a list 
60
-  // of remote nodes (via cmRtNetCreateNode()) and a list of local endpoints 
61
-  // (cmRtNetRegisterEndpoint()).  During sync mode a node sends it's local 
62
-  // endpoint list to each registered remote node. When a remote node receives 
63
-  // an endpoint it updates it's own remote node/endpoint 
64
-  // list.
65
-  cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
59
+  cmRtNetRC_t cmRtNetFinalize( cmRtNetH_t h );
66
 
60
 
61
+  // Broadcast the 'hello' to all machines listening on the 
62
+  // broadcast addresss. This starts the synchronization sequence
63
+  cmRtNetRC_t cmRtNetDoSync( cmRtNetH_t h );
67
 
64
 
68
   // This function must be polled to receive incoming network messages
65
   // This function must be polled to receive incoming network messages
69
   // via the callback funcion 'cbFunc' as passed to cmRtNetAlloc()
66
   // via the callback funcion 'cbFunc' as passed to cmRtNetAlloc()
70
   cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
67
   cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
71
 
68
 
72
-  bool        cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt );
69
+  // Get an end point handle for use with cmRtNetSend.
70
+  cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp );
73
 
71
 
74
-  unsigned  cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel );
75
-  
72
+  // Send a message to a remote endpoint.
73
+  cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt );
76
 
74
 
77
-  cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, unsigned endPointIndex, const void* msg, unsigned msgByteCnt );
75
+  // Send a message to a remote endpoint. This function is a composite
76
+  // of cmRtNetEndpointHandle() and cmRtNetSend().
77
+  cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt );
78
 
78
 
79
-  void      cmRtNetReport( cmRtNetH_t h );
79
+  // Enable/disable synchronization protocol reporting.
80
+  // Return the previous state of the report sync. flag.
81
+  bool        cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl );
82
+  bool        cmRtNetReportSyncIsEnabled( cmRtNetH_t h );
83
+
84
+  void        cmRtNetReport( cmRtNetH_t h );
80
     
85
     
81
-  void      cmRtNetTest( cmCtx_t* ctx, bool mstrFl );
86
+  void        cmRtNetTest( cmCtx_t* ctx, bool mstrFl );
82
 
87
 
83
   /*
88
   /*
84
-    Master:
85
-      cmRtNetBeginSyncMode().
86
-      while( cmRtNetIsSyncMode())
87
-      {
88
-       // Give the master an oppurtunity to advance it's sync mode state.
89
-       // When the master is has sync'd with all remote nodes in it's
90
-       // remote node list then it will automatically exit sync mode.
91
-       cmRtNetSyncModeSend()
92
-      }
93
-
94
-      _myNetRecv(dataV,dataN,addr)
95
-     {
96
-       if( cmRtNetIsSyncModeMsg(dataV,dataN) )
97
-         cmRtNetSyncModeRecv(dataV,dataN,addr)
98
-     } 
99
-
100
-
101
-     The 'master' is the machine which cmRtNetBeginSyncMode() is called on.
102
-     1) 'master' sends local endpoints to all registered remote nodes.
103
-     2) When a 'slave' receives the kDoneSelNetId msg it transmits
104
-     it's own local endpoints back to the master.
105
-
106
-     a. Each node in the node list has a type id:
107
-       1. local 
108
-       2. registered - remote node that was explicitely registered on a master
109
-       3. received   - remote node that was received from a master
110
-
111
-     b. 
112
-       1. All nodes are created in the 'send-hello' state.
113
-       2. If a master machine is in 'sync-mode' then it systematically sends
114
-       each of it's local endpoints to all 'registered' nodes.
115
-       3. When a slave machine recives a 'hello' it creates a
116
-       'received' node.
117
-       4. When a slave machine recieves a 'done' it enters sync mode
118
-       and systematically sends each of its local endpoints to
119
-       the 'done' source.
120
-       
121
-
122
-   Protocol:
123
-     1.  A: on init bcast 'hello'
124
-     2.  B: on 'hello'     -  create node-A w/ ei=0      - send 'node'
125
-     3.  A: on 'node'      -  create node-B w/ ei=0      - send first 'endpt'
126
-     4.  B: on 'endpt'     -  create endpt on node-A     - ei!=en ? send 'endpt' or send 'done'
127
-     5.  A: on 'endpt'     -  create endpt on node-B     - ei!=en ? send 'endpt' or send 'done'
128
-     6.  B: on 'done'      -  mark node-A as 'valid'
129
-     7.  A: on 'done'      -  mark node-B as 'valid'.
89
+
90
+   Synchronization Protocol:
91
+
92
+                  Machine A                          Machine B
93
+     ==================================    ====================================
94
+     broadcast 'hello' --------------------> create node-A w/ ei=0 -------+
95
+                                                                          |
96
+     +<-- create node-B w/ ei=0 <----------- send 'node' <----------------+
97
+     |
98
+     +--> switch(ei,m_t)
99
+     |     ei  < en   : send endpt[ei++] ---> create endpt[] on node-A -->+
100
+     |                                                                    |
101
+     |     ei == en   : ++ei,send 'done' -------------------------------->+                                                    |
102
+     |                                                                    |
103
+     |    m_t!='done' :      send 'done' -------------------------------->+                                                              |
104
+     |                                                                    |
105
+     |    (stop)      :                                                   |
106
+     |                                                                    |
107
+     |                                                                    v
108
+     |                                                           switch(ei,m_t)
109
+     +<-- create endpt[] on node-B  <--------- send endpt[ei++] : ei < en
110
+     | 
111
+     +<--------------------------------------- send 'done',++ei : ei == en 
112
+     |
113
+     +<--------------------------------------- send 'done'      : m_t!= 'done'
114
+                                                                  
115
+                                                                :  (stop)
116
+
117
+     Notes:
118
+        1)  'ei' is the index of the next local end point to transmit.
119
+        2)  'en' is the count of local endpoints.
120
+        3)  'm_t' is the msg type (i.e.'hello','node','endpoint','done') 
121
+            of the incoming message.
130
 
122
 
131
    */  
123
    */  
132
 
124
 

Laden…
Annuleren
Opslaan