Esempio n. 1
0
CTEST2(tube, send_pdec)
{
    tube *t;
    uint8_t ip[]   = {192, 168, 0, 0};
    uint8_t token[] = {42, 42, 42, 42, 42};
    char url[]= "http://example.com";
    struct sockaddr_in6 remoteAddr;
    cn_cbor_context ctx;
    cn_cbor *map;

    ASSERT_TRUE(ls_sockaddr_get_remote_ip_addr("127.0.0.1",
                                               "1402",
                                               (struct sockaddr*)&remoteAddr,
                                               sizeof(remoteAddr),
                                               &data->err));

    ASSERT_TRUE( tube_manager_open_tube(data->mgr, (const struct sockaddr*)&remoteAddr, &t, &data->err));

    ASSERT_TRUE(path_mandatory_keys_create(ip, sizeof(ip), token, sizeof(token), url, &ctx, &map, &data->err));

    ASSERT_TRUE( tube_send_pdec(t,map,true, &data->err) );

    ls_pool_destroy((ls_pool*)ctx.context);

    tube_manager_remove(data->mgr, t);
    ASSERT_EQUAL(tube_manager_size(data->mgr), 0);
}
Esempio n. 2
0
CTEST2(tube, tube_data)
{
    tube *t;
    uint8_t udata[] = "SPUD_makeUBES_FUN";
    struct sockaddr_storage remoteAddr;
    ASSERT_TRUE( ls_sockaddr_get_remote_ip_addr("127.0.0.1",
                                                "1402",
                                                (struct sockaddr*)&remoteAddr,
                                                sizeof(remoteAddr),
                                                &data->err));

    ASSERT_TRUE( tube_manager_open_tube(data->mgr, (const struct sockaddr*)&remoteAddr, &t, &data->err));

    ASSERT_TRUE( tube_data(t,
                           udata,
                           17,
                           &data->err));

    ASSERT_TRUE( tube_data(t,
                           NULL,
                           0,
                           &data->err));
    tube_manager_remove(data->mgr, t);
    ASSERT_EQUAL(tube_manager_size(data->mgr), 0);
}
Esempio n. 3
0
CTEST2(tube, close)
{
    tube *t;
    struct sockaddr_in6 remoteAddr;

    ASSERT_TRUE( ls_sockaddr_get_remote_ip_addr("127.0.0.1",
                                                "1402",
                                                (struct sockaddr *)&remoteAddr,
                                                sizeof(remoteAddr),
                                                &data->err));

    ASSERT_TRUE( tube_manager_open_tube(data->mgr, (const struct sockaddr*)&remoteAddr, &t, &data->err));
    ASSERT_TRUE( tube_close(t, &data->err));
}
Esempio n. 4
0
CTEST2(tube, open)
{
    tube *t;
	ls_pktinfo *pi;
	struct in_pktinfo info4;
    struct sockaddr_in6 remoteAddr;
    ASSERT_TRUE( ls_sockaddr_get_remote_ip_addr("::1",
                                                "1402",
                                                (struct sockaddr*)&remoteAddr,
                                                sizeof(remoteAddr),
                                                &data->err));

    ASSERT_TRUE( tube_manager_open_tube(data->mgr, (const struct sockaddr*)&remoteAddr, &t, &data->err));
    ASSERT_EQUAL(tube_manager_size(data->mgr), 1);


	ASSERT_TRUE(ls_pktinfo_create(&pi, &data->err));
    info4.ipi_addr.s_addr = htonl(0x7f000001);
    ls_pktinfo_set4(pi, &info4);
	tube_set_local(t, pi, &data->err);
	ASSERT_TRUE( tube_print(t, &data->err));
}
Esempio n. 5
0
static void
loopstart_cb(ls_event_data* evt,
             void*          arg)
{
  ls_err err;
  UNUSED_PARAM(evt);
  UNUSED_PARAM(arg);

  if ( !tube_manager_open_tube(mgr,
                               (const struct sockaddr*)&config.remoteAddr,
                               &config.t,
                               &err) )
  {
    LS_LOG_ERR(err, "tube_open");
    return;
  }

  if ( !tube_print(config.t, &err) )
  {
    LS_LOG_ERR(err, "tube_print");
    return;
  }
}
Esempio n. 6
0
static int
markov()
{
  struct timespec timer;
  struct timespec remaining;
  tube*           t;
  ls_err          err;
  int             i;
  int*            iptr;

  timer.tv_sec = 0;

  while ( tube_manager_running(mgr) )
  {
    timer.tv_nsec = gauss(50000000, 10000000);
    nanosleep(&timer, &remaining);
    i = random() % NUM_TUBES;
    t = tubes[i];
    if (!t)
    {
      if ( !tube_create(&t, &err) )
      {
        LS_LOG_ERR(err, "tube_create");
        return 1;
      }
      tubes[i] = t;
      iptr     = malloc( sizeof(*iptr) );
      *iptr    = i;
      tube_set_data(t, iptr);
    }
    switch ( tube_get_state(t) )
    {
    case TS_START:
      ls_log(LS_LOG_ERROR, "invalid tube state");
      return 1;
    case TS_UNKNOWN:
      if ( !tube_manager_open_tube(mgr,
                                   (const struct sockaddr*)&remoteAddr,
                                   &t,
                                   &err) )
      {
        LS_LOG_ERR(err, "tube_manager_open_tube");
        return 1;
      }
      break;
    case TS_OPENING:
      /* keep waiting by the mailbox, Charlie Brown */
      break;
    case TS_RUNNING:
      /* .1% chance of close */
      if ( (random() % 10000) < 10 )
      {
        if ( !tube_close(t, &err) )
        {
          LS_LOG_ERR(err, "tube_close");
          return 1;
        }
      }
      else
      {
        /* TODO: put something intersting in the buffer */
        if ( !tube_data(t, data, random() % sizeof(data), &err) )
        {
          LS_LOG_ERR(err, "tube_data");
          return 1;
        }
      }
    case TS_RESUMING:
      /* can't get here yet */
      break;
    }
  }
  return 0;
}