Add client_initiate_connection fn, some fixes
This commit is contained in:
parent
f10521ec52
commit
d027b1703a
3 changed files with 37 additions and 4 deletions
|
@ -29,6 +29,7 @@ namespace UDPC {
|
|||
|
||||
static const auto ONE_SECOND = std::chrono::seconds(1);
|
||||
static const auto TEN_SECONDS = std::chrono::seconds(10);
|
||||
static const auto THIRTY_SECONDS = std::chrono::seconds(30);
|
||||
|
||||
static uint32_t LOCAL_ADDR = 0;
|
||||
static const auto INIT_PKT_INTERVAL_DT = std::chrono::seconds(5);
|
||||
|
|
|
@ -50,8 +50,12 @@ std::size_t UDPC::ConnectionIdentifier::Hasher::operator()(const ConnectionIdent
|
|||
|
||||
UDPC::ConnectionData::ConnectionData() :
|
||||
flags(),
|
||||
id(0),
|
||||
lseq(0),
|
||||
rseq(0),
|
||||
ack(0xFFFFFFFF),
|
||||
timer(std::chrono::steady_clock::duration::zero()),
|
||||
toggleT(std::chrono::seconds(30)),
|
||||
toggleT(UDPC::THIRTY_SECONDS),
|
||||
toggleTimer(std::chrono::steady_clock::duration::zero()),
|
||||
toggledTimer(std::chrono::steady_clock::duration::zero()),
|
||||
sentPkts(),
|
||||
|
@ -68,10 +72,12 @@ rtt(std::chrono::steady_clock::duration::zero())
|
|||
UDPC::ConnectionData::ConnectionData(bool isServer, Context *ctx) :
|
||||
UDPC::ConnectionData::ConnectionData()
|
||||
{
|
||||
if(isServer) {
|
||||
flags.set(3);
|
||||
if(isServer) {
|
||||
id = UDPC::generateConnectionID(*ctx);
|
||||
flags.set(4);
|
||||
} else {
|
||||
lseq = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -770,6 +776,29 @@ void UDPC_update(void *ctx) {
|
|||
}
|
||||
}
|
||||
|
||||
void UDPC_client_initiate_connection(void *ctx, uint32_t addr, uint16_t port) {
|
||||
UDPC::Context *c = UDPC::verifyContext(ctx);
|
||||
if(!c || !c->flags.test(1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UDPC::ConnectionData newCon(false, c);
|
||||
UDPC::ConnectionIdentifier identifier(addr, port);
|
||||
|
||||
// TODO make thread safe by using mutex
|
||||
c->conMap.insert(std::make_pair(identifier, std::move(newCon)));
|
||||
auto addrConIter = c->addrConMap.find(addr);
|
||||
if(addrConIter == c->addrConMap.end()) {
|
||||
auto insertResult = c->addrConMap.insert(std::make_pair(
|
||||
addr,
|
||||
std::unordered_set<UDPC::ConnectionIdentifier, UDPC::ConnectionIdentifier::Hasher>{}
|
||||
));
|
||||
assert(insertResult.second);
|
||||
addrConIter = insertResult.first;
|
||||
}
|
||||
addrConIter->second.insert(identifier);
|
||||
}
|
||||
|
||||
int UDPC_get_queue_send_available(void *ctx, uint32_t addr, uint16_t port) {
|
||||
UDPC::Context *c = UDPC::verifyContext(ctx);
|
||||
if(!c) {
|
||||
|
|
|
@ -73,10 +73,13 @@ void UDPC_destroy(void *ctx);
|
|||
|
||||
void UDPC_update(void *ctx);
|
||||
|
||||
/// port must be in native byte order, addr must be in network byte order (big-endian)
|
||||
/// addr must be in network byte order (big-endian), port must be in native byte order
|
||||
void UDPC_client_initiate_connection(void *ctx, uint32_t addr, uint16_t port);
|
||||
|
||||
/// addr must be in network byte order (big-endian), port must be in native byte order
|
||||
int UDPC_get_queue_send_available(void *ctx, uint32_t addr, uint16_t port);
|
||||
|
||||
/// destPort must be in native byte order, destAddr must be in network byte order (big-endian)
|
||||
/// destAddr must be in network byte order (big-endian), destPort must be in native byte order
|
||||
void UDPC_queue_send(void *ctx, uint32_t destAddr, uint16_t destPort,
|
||||
uint32_t isChecked, void *data, uint32_t size);
|
||||
|
||||
|
|
Loading…
Reference in a new issue