mirror of
https://gitea.invidious.io/iv-org/litespeed-quic.git
synced 2024-08-15 00:53:43 +00:00
Use the original method of tracking connections by CIDs by default. If zero-sized CID support is turned on, connections are tracked by the address. A new connection is not created if another connection is using the same network address.
82 lines
2 KiB
C
82 lines
2 KiB
C
/* Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc. See LICENSE. */
|
|
#include <assert.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/queue.h>
|
|
#ifndef WIN32
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include "lsquic.h"
|
|
#include "lsquic_int_types.h"
|
|
#include "lsquic_types.h"
|
|
#include "lsquic_conn.h"
|
|
#include "lsquic_conn_hash.h"
|
|
#include "lsquic_mm.h"
|
|
#include "lsquic_malo.h"
|
|
#include "lsquic_logger.h"
|
|
#include "lsquic.h"
|
|
|
|
|
|
static struct lsquic_conn *
|
|
get_new_lsquic_conn (struct malo *malo)
|
|
{
|
|
struct lsquic_conn *lconn = lsquic_malo_get(malo);
|
|
memset(lconn, 0, sizeof(*lconn));
|
|
lconn->cn_cid = (uintptr_t) lconn;
|
|
return lconn;
|
|
}
|
|
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
struct malo *malo;
|
|
struct conn_hash conn_hash;
|
|
unsigned n, nelems;
|
|
struct lsquic_conn *lconn, *find_lsconn;
|
|
int s;
|
|
|
|
if (argc > 1)
|
|
nelems = atoi(argv[1]);
|
|
else
|
|
nelems = 1000000;
|
|
|
|
lsquic_log_to_fstream(stderr, LLTS_HHMMSSMS);
|
|
lsquic_set_log_level("info");
|
|
|
|
malo = lsquic_malo_create(sizeof(*lconn));
|
|
s = conn_hash_init(&conn_hash, 0);
|
|
assert(0 == s);
|
|
|
|
for (n = 0; n < nelems; ++n)
|
|
{
|
|
lconn = get_new_lsquic_conn(malo);
|
|
lconn->cn_if = (void *) (uintptr_t) n; /* This will be used for verification later the test */
|
|
find_lsconn = conn_hash_find_by_cid(&conn_hash, lconn->cn_cid);
|
|
assert(!find_lsconn);
|
|
s = conn_hash_add(&conn_hash, lconn);
|
|
assert(0 == s);
|
|
}
|
|
|
|
assert(nelems == conn_hash_count(&conn_hash));
|
|
|
|
for (lconn = lsquic_malo_first(malo); lconn;
|
|
lconn = lsquic_malo_next(malo))
|
|
{
|
|
find_lsconn = conn_hash_find_by_cid(&conn_hash, lconn->cn_cid);
|
|
assert(find_lsconn == lconn);
|
|
conn_hash_remove(&conn_hash, lconn);
|
|
find_lsconn = conn_hash_find_by_cid(&conn_hash, lconn->cn_cid);
|
|
assert(!find_lsconn);
|
|
}
|
|
|
|
assert(0 == conn_hash_count(&conn_hash));
|
|
|
|
conn_hash_cleanup(&conn_hash);
|
|
lsquic_malo_destroy(malo);
|
|
|
|
exit(0);
|
|
}
|