Back to index

citadel  8.12
Classes | Typedefs | Functions
netconfig.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _nodeconf
struct  __NetMap

Typedefs

typedef struct _nodeconf NodeConf
typedef struct __NetMap NetMap

Functions

HashList * load_ignetcfg (void)
HashList * read_network_map (void)
StrBuf * SerializeNetworkMap (HashList *Map)
void network_learn_topology (char *node, char *path, HashList *the_netmap, int *netmap_changed)
int is_valid_node (const StrBuf **nexthop, const StrBuf **secret, StrBuf *node, HashList *IgnetCfg, HashList *the_netmap)

Class Documentation

struct _nodeconf

Definition at line 30 of file netconfig.h.

Class Members
int DeleteMe
StrBuf * Host
StrBuf * NodeName
StrBuf * Port
StrBuf * Secret
struct __NetMap

Definition at line 38 of file netconfig.h.

Class Members
time_t lastcontact
StrBuf * NextHop
StrBuf * NodeName

Typedef Documentation

typedef struct __NetMap NetMap
typedef struct _nodeconf NodeConf

Function Documentation

int is_valid_node ( const StrBuf **  nexthop,
const StrBuf **  secret,
StrBuf *  node,
HashList *  IgnetCfg,
HashList *  the_netmap 
)

Definition at line 299 of file serv_netconfig.c.

{
       void *vNetMap;
       void *vNodeConf;
       NodeConf *TheNode;
       NetMap *TheNetMap;

       if (StrLength(node) == 0) {
              return(-1);
       }

       /*
        * First try the neighbor nodes
        */
       if (GetCount(IgnetCfg) == 0) {
              syslog(LOG_INFO, "IgnetCfg is empty!\n");
              if (nexthop != NULL) {
                     *nexthop = NULL;
              }
              return(-1);
       }

       /* try to find a neigbour with the name 'node' */
       if (GetHash(IgnetCfg, SKEY(node), &vNodeConf) && 
           (vNodeConf != NULL))
       {
              TheNode = (NodeConf*)vNodeConf;
              if (secret != NULL)
                     *secret = TheNode->Secret;
              return 0;            /* yup, it's a direct neighbor */
       }

       /*
        * If we get to this point we have to see if we know the next hop
        *//* TODO: is the NodeName Uniq? */
       if ((GetCount(the_netmap) > 0) &&
           (GetHash(the_netmap, SKEY(node), &vNetMap)))
       {
              TheNetMap = (NetMap*)vNetMap;
              if (nexthop != NULL)
                     *nexthop = TheNetMap->NextHop;
              return(0);
       }

       /*
        * If we get to this point, the supplied node name is bogus.
        */
       syslog(LOG_ERR, "Invalid node name <%s>\n", ChrPtr(node));
       return(-1);
}

Here is the caller graph for this function:

HashList* load_ignetcfg ( void  )

Definition at line 136 of file serv_netconfig.c.

{
       const char *LinePos;
       char       *Cfg;
       StrBuf     *Buf;
       StrBuf     *LineBuf;
       HashList   *Hash;
       NodeConf   *Node;

       Cfg =  CtdlGetSysConfig(IGNETCFG);
       if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
              if (Cfg != NULL)
                     free(Cfg);
              return NULL;
       }

       Hash = NewHash(1, NULL);
       Buf = NewStrBufPlain(Cfg, -1);
       free(Cfg);
       LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
       LinePos = NULL;
       do
       {
              StrBufSipLine(LineBuf, Buf, &LinePos);
              if (StrLength(LineBuf) != 0) {
                     Node = NewNode(LineBuf);
                     if (Node != NULL) {
                            Put(Hash, SKEY(Node->NodeName), Node, DeleteNodeConf);
                     }
              }
       } while (LinePos != StrBufNOTNULL);
       FreeStrBuf(&Buf);
       FreeStrBuf(&LineBuf);
       return Hash;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void network_learn_topology ( char *  node,
char *  path,
HashList *  the_netmap,
int *  netmap_changed 
)

Definition at line 262 of file serv_netconfig.c.

{
       NetMap *pNM = NULL;
       void *vptr;
       char nexthop[256];
       NetMap *nmptr;

       if (GetHash(the_netmap, node, strlen(node), &vptr) && 
           (vptr != NULL))/* TODO: is the NodeName Uniq? */
       {
              pNM = (NetMap*)vptr;
              extract_token(nexthop, path, 0, '!', sizeof nexthop);
              if (!strcmp(nexthop, ChrPtr(pNM->NextHop))) {
                     pNM->lastcontact = time(NULL);
                     (*netmap_changed) ++;
                     return;
              }
       }

       /* If we got here then it's not in the map, so add it. */
       nmptr = (NetMap *) malloc(sizeof (NetMap));
       nmptr->NodeName = NewStrBufPlain(node, -1);
       nmptr->lastcontact = time(NULL);
       nmptr->NextHop = NewStrBuf ();
       StrBufExtract_tokenFromStr(nmptr->NextHop, path, strlen(path), 0, '!');
       /* TODO: is the NodeName Uniq? */
       Put(the_netmap, SKEY(nmptr->NodeName), nmptr, DeleteNetMap);
       (*netmap_changed) ++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HashList* read_network_map ( void  )

Definition at line 201 of file serv_netconfig.c.

{
       const char *LinePos;
       char       *Cfg;
       StrBuf     *Buf;
       StrBuf     *LineBuf;
       HashList   *Hash;
       NetMap     *TheNetMap;

       Cfg =  CtdlGetSysConfig(IGNETMAP);
       if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
              if (Cfg != NULL)
                     free(Cfg);
              return NULL;
       }

       Hash = NewHash(1, NULL);
       Buf = NewStrBufPlain(Cfg, -1);
       free(Cfg);
       LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
       LinePos = NULL;
       while (StrBufSipLine(Buf, LineBuf, &LinePos))
       {
              TheNetMap = NewNetMap(LineBuf);
              if (TheNetMap != NULL) { /* TODO: is the NodeName Uniq? */
                     Put(Hash, SKEY(TheNetMap->NodeName), TheNetMap, DeleteNetMap);
              }
       }
       FreeStrBuf(&Buf);
       FreeStrBuf(&LineBuf);
       return Hash;
}

Here is the call graph for this function:

Here is the caller graph for this function:

StrBuf* SerializeNetworkMap ( HashList *  Map)

Definition at line 234 of file serv_netconfig.c.

{
       void *vMap;
       const char *key;
       long len;
       StrBuf *Ret = NewStrBuf();
       HashPos *Pos = GetNewHashPos(Map, 0);

       while (GetNextHashPos(Map, Pos, &len, &key, &vMap))
       {
              NetMap *pMap = (NetMap*) vMap;
              StrBufAppendBuf(Ret, pMap->NodeName, 0);
              StrBufAppendBufPlain(Ret, HKEY("|"), 0);

              StrBufAppendPrintf(Ret, "%ld", pMap->lastcontact, 0);
              StrBufAppendBufPlain(Ret, HKEY("|"), 0);

              StrBufAppendBuf(Ret, pMap->NextHop, 0);
              StrBufAppendBufPlain(Ret, HKEY("\n"), 0);
       }
       DeleteHashPos(&Pos);
       return Ret;
}

Here is the caller graph for this function: