/*---------------------------------------------------------------------------*/
static void
handle_incoming_reg(const uip_ipaddr_t *owner, servreg_hack_id_t id, uint8_t seqno)
{
  servreg_hack_item_t *t;
  struct servreg_hack_registration *r;

  /* Walk through list, see if we already have a service ID
     registered. If so, we do different things depending on the seqno
     of the update: if the seqno is older than what we have, we
     discard the incoming registration. If the seqno is newer than
     what we have, we reset the lifetime timer of the current
     registration.

     If we did not have the service registered already, we allocate a
     new registration and put it on our list. If we cannot allocate a
     service registration, we discard the incoming registration (for
     now - we might later choose to discard the oldest registration
     that we have). */

  for(t = servreg_hack_list_head();
      t != NULL;
      t = list_item_next(t)) {
    if(servreg_hack_item_id(t) == id) {
      r = t;
      if(SEQNO_LT(r->seqno, seqno)) {
        r->seqno = seqno;
        timer_set(&r->timer, LIFETIME);

        /* Put item first on list, so that subsequent lookups will
           find this one. */
        list_remove(others_services, r);
        list_push(others_services, r);
      }
      return;
    }
  }

  r = memb_alloc(&registrations);
  if(r == NULL) {
    printf("servreg_hack_register: error, could not allocate memory, should reclaim another registration but this has not been implemented yet.\n");
    return;
  }
  r->id = id;
  r->seqno = 1;
  uip_ipaddr_copy(&r->addr, owner);
  timer_set(&r->timer, LIFETIME);
  list_add(others_services, r);
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
static void
recv(struct udp_socket *c, void *ptr,
     const uip_ipaddr_t *source_addr, uint16_t source_port,
     const uip_ipaddr_t *dest_addr, uint16_t dest_port,
     const uint8_t *data, uint16_t datalen)
{
  struct propple_socket *s = ptr;
  struct propple_msg *m = (struct propple_msg *)data;
  struct propple_hdr h;

  memcpy((uint8_t *)&h, (uint8_t *)&m->h, sizeof(h));

  uint16_t seqno = h.seqno;

  printf("propple-socket: recv seqno %d our %d data len %d\n",
	 seqno,
         s->seqno,
	 datalen);

  if(seqno == s->seqno) {
    /*    c->cb->recv(c);*/
    ++s->duplicates;
  } else if(SEQNO_LT(seqno, s->seqno)) {
    s->interval_scaling = 0;
    send(s);
  } else { /* hdr->seqno > c->seqno */
    /* Sanity check datalen */
    if(h.datalen <= PROPPLE_MAXDATALEN) {
      s->seqno = seqno;
      /* Remember the incoming data */
      memcpy(s->data, m->data, h.datalen);
      s->datalen = h.datalen;
      s->interval_scaling = 0;
      reset_interval(s);
      ctimer_set(&s->first_transmission_timer,
                 random_rand() % s->interval,
                 send, s);

      if(s->callback != NULL) {
        s->callback(s, s->ptr, s->seqno,
                    s->data, s->datalen);
      }
      /*    c->cb->recv(c);*/
    }
  }
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
static void
recv(struct broadcast_conn *bc, const rimeaddr_t *from)
{
    struct trickle_conn *c = (struct trickle_conn *)bc;
    uint16_t seqno = packetbuf_attr(PACKETBUF_ATTR_EPACKET_ID);

    PRINTF("%d.%d: trickle recv seqno %d from %d.%d our %d data len %d channel %d\n",
           rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
           seqno,
           from->u8[0], from->u8[1],
           c->seqno,
           packetbuf_datalen(),
           packetbuf_attr(PACKETBUF_ATTR_CHANNEL));

    if(seqno == c->seqno)
    {
        /*    c->cb->recv(c);*/
        ++c->duplicates;
    }
    else if(SEQNO_LT(seqno, c->seqno))
    {
        c->interval_scaling = 0;
        send(c);
    }
    else     /* hdr->seqno > c->seqno */
    {
#if CONTIKI_TARGET_NETSIM
        /*    ether_set_line(from->u8[0], from->u8[1]);*/
#endif /* CONTIKI_TARGET_NETSIM */
        c->seqno = seqno;
        /* Store the incoming data in the queuebuf */
        if(c->q != NULL)
        {
            queuebuf_free(c->q);
        }
        c->q = queuebuf_new_from_packetbuf();
        c->interval_scaling = 0;
        reset_interval(c);
        ctimer_set(&c->first_transmission_timer, random_rand() % c->interval,
                   send, c);
        c->cb->recv(c);
    }
}