Esempio n. 1
0
void net_serial_free(net_serial_t net)
{
  if(!net) return;
  // TODO free pipes!
  xht_free(net->pipes);
  free(net);
  return;
}
Esempio n. 2
0
void thtp_free(switch_t s)
{
  thtp_t t = thtp_get(s);
  //xht_walk() TODO free all notes
  // free all globs
  xht_free(t->index);
  free(t);
}
Esempio n. 3
0
File: tcp4.c Progetto: fd/telehash-c
void net_tcp4_free(net_tcp4_t net)
{
  if(!net) return;
  close(net->server);
  xht_free(net->pipes);
  lob_free(net->path);
  free(net);
  return;
}
Esempio n. 4
0
File: link.c Progetto: fd/telehash-c
void link_free(link_t link)
{
  if(!link) return;
  LOG("dropping link %s",link->id->hashname);
  xht_set(link->mesh->index,link->id->hashname,NULL);

  // TODO go through ->pipes

  // TODO go through link->channels
  xht_free(link->channels);
  xht_free(link->index);

  hashname_free(link->id);
  if(link->x)
  {
    xht_set(link->mesh->index,link->token,NULL);
    exchange3_free(link->x);
  }
  free(link);
}
Esempio n. 5
0
mesh_t mesh_free(mesh_t mesh)
{
  on_t on;
  if(!mesh) return NULL;

  // free all links first
  link_t link, next;
  for(link = mesh->links;link;link = next)
  {
    next = link->next;
    link_free(link);
  }
  
  // free any triggers first
  while(mesh->on)
  {
    on = mesh->on;
    mesh->on = on->next;
    if(on->free) on->free(mesh);
    free(on->id);
    free(on);
  }

  xht_free(mesh->index);
  lob_free(mesh->keys);
  lob_free(mesh->paths);
  lob_freeall(mesh->cached);
  hashname_free(mesh->id);
  e3x_self_free(mesh->self);
  if(mesh->uri) free(mesh->uri);
  if(mesh->ipv4_local) free(mesh->ipv4_local);
  if(mesh->ipv4_public) free(mesh->ipv4_public);

  free(mesh);
  return NULL;
}
Esempio n. 6
0
int main(int argc, char *argv[])
{
    mdnsd d;
    mdnsdr r;
    struct message m;
    unsigned long int ip;
    unsigned short int port;
    struct timeval *tv;
    int bsize, ssize = sizeof(struct sockaddr_in);
    unsigned char buf[MAX_PACKET_LEN];
    struct sockaddr_in from, to;
    fd_set fds;
    int s;
    unsigned char *packet, hlocal[256], nlocal[256];
    int len = 0;
    xht h;

    if(argc < 4) { printf("usage: mhttp 'unique name' 12.34.56.78 80 '/optionalpath'\n"); return; }

    ip = inet_addr(argv[2]);
    port = atoi(argv[3]);
    printf("Announcing .local site named '%s' to %s:%d and extra path '%s'\n",argv[1],inet_ntoa(ip),port,argv[4]);

    signal(SIGINT,done);
    signal(SIGHUP,done);
    signal(SIGQUIT,done);
    signal(SIGTERM,done);
    pipe(_zzz);
    _d = d = mdnsd_new(1,1000);
    if((s = msock()) == 0) { printf("can't create socket: %s\n",strerror(errno)); return 1; }

    sprintf(hlocal,"%s._http._tcp.local.",argv[1]);
    sprintf(nlocal,"http-%s.local.",argv[1]);
    r = mdnsd_shared(d,"_http._tcp.local.",QTYPE_PTR,120);
    mdnsd_set_host(d,r,hlocal);
    r = mdnsd_unique(d,hlocal,QTYPE_SRV,600,con,0);
    mdnsd_set_srv(d,r,0,0,port,nlocal);
    r = mdnsd_unique(d,nlocal,QTYPE_A,600,con,0);
    mdnsd_set_raw(d,r,(unsigned char *)&ip,4);
    r = mdnsd_unique(d,hlocal,16,600,con,0);
    h = xht_new(11);
    if(argc == 5 && argv[4] && strlen(argv[4]) > 0) xht_set(h,"path",argv[4]);
    packet = sd2txt(h, &len);
    xht_free(h);
    mdnsd_set_raw(d,r,packet,len);
    free(packet);

    while(1)
    {
        tv = mdnsd_sleep(d);
        FD_ZERO(&fds);
        FD_SET(_zzz[0],&fds);
        FD_SET(s,&fds);
        select(s+1,&fds,0,0,tv);

        // only used when we wake-up from a signal, shutting down
        if(FD_ISSET(_zzz[0],&fds)) read(_zzz[0],buf,MAX_PACKET_LEN);

        if(FD_ISSET(s,&fds))
        {
            while((bsize = recvfrom(s,buf,MAX_PACKET_LEN,0,(struct sockaddr*)&from,&ssize)) > 0)
            {
                bzero(&m,sizeof(struct message));
                message_parse(&m,buf);
                mdnsd_in(d,&m,(unsigned long int)from.sin_addr.s_addr,from.sin_port);
            }
            if(bsize < 0 && errno != EAGAIN) { printf("can't read from socket %d: %s\n",errno,strerror(errno)); return 1; }
        }
        while(mdnsd_out(d,&m,&ip,&port))
        {
            bzero(&to, sizeof(to));
            to.sin_family = AF_INET;
            to.sin_port = port;
            to.sin_addr.s_addr = ip;
            if(sendto(s,message_packet(&m),message_packet_len(&m),0,(struct sockaddr *)&to,sizeof(struct sockaddr_in)) != message_packet_len(&m))  { printf("can't write to socket: %s\n",strerror(errno)); return 1; }
        }
        if(_shutdown) break;
    }

    mdnsd_shutdown(d);
    mdnsd_free(d);
    return 0;
}