1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-11-28 05:41:06 +00:00

Added key exchange to LAIKA_HANDSHAKE_*

- test keys are defined in laika.h
- bug fixes & refactoring with laikaM_growarray()
This commit is contained in:
2022-01-27 19:55:28 -06:00
parent 203b5ce38f
commit a023929190
11 changed files with 129 additions and 15 deletions

View File

@@ -10,12 +10,19 @@ struct sLaika_peer *laikaS_newPeer(void (*pktHandler)(struct sLaika_peer *peer,
peer->pktSizeTable = pktSizeTable;
peer->pList = pList;
peer->uData = uData;
peer->priv = NULL;
peer->pub = NULL;
peer->pktSize = 0;
peer->pktID = LAIKAPKT_MAXNONE;
peer->setPollOut = false;
return peer;
}
void laikaS_setKeys(struct sLaika_peer *peer, uint8_t *priv, uint8_t *pub) {
peer->priv = priv;
peer->pub = pub;
}
void laikaS_freePeer(struct sLaika_peer *peer) {
laikaS_cleanSocket(&peer->sock);
laikaM_free(peer);

View File

@@ -66,7 +66,7 @@ void laikaP_addSock(struct sLaika_pollList *pList, struct sLaika_socket *sock) {
#else
/* allocate space in array & add PollFD */
laikaM_growarray(PollFD, pList->fds, pList->fdCount, pList->fdCapacity);
laikaM_growarray(PollFD, pList->fds, 1, pList->fdCount, pList->fdCapacity);
pList->fds[pList->fdCount++] = (PollFD){sock->sock, POLLIN};
#endif
}
@@ -152,7 +152,7 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
for (i = 0; i < nEvents; i++) {
/* add event to revent array */
laikaM_growarray(struct sLaika_pollEvent, pList->revents, pList->reventCount, pList->reventCapacity);
laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity);
pList->revents[pList->reventCount++] = (struct sLaika_pollEvent){
.sock = pList->ep_events[i].data.ptr,
.pollIn = pList->ep_events[i].events & EPOLLIN,
@@ -173,7 +173,7 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
struct sLaika_socket *sock = hashmap_get(pList->sockets, &(tLaika_hashMapElem){.fd = (SOCKET)pfd.fd});
/* insert event into revents array */
laikaM_growarray(struct sLaika_pollEvent, pList->revents, pList->reventCount, pList->reventCapacity);
laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity);
pList->revents[pList->reventCount++] = (struct sLaika_pollEvent){
.sock = sock,
.pollIn = pfd.revents & POLLIN,

View File

@@ -177,7 +177,7 @@ void laikaS_read(struct sLaika_socket *sock, void *buf, size_t sz) {
void laikaS_write(struct sLaika_socket *sock, void *buf, size_t sz) {
/* make sure we have enough space to copy the buffer */
laikaM_growarray(uint8_t, sock->outBuf, sock->outCount + sz, sock->outCap);\
laikaM_growarray(uint8_t, sock->outBuf, sz, sock->outCount, sock->outCap);\
/* copy the buffer, then increment outCount */
memcpy(&sock->outBuf[sock->outCount], buf, sz);
@@ -185,7 +185,7 @@ void laikaS_write(struct sLaika_socket *sock, void *buf, size_t sz) {
}
void laikaS_writeByte(struct sLaika_socket *sock, uint8_t data) {
laikaM_growarray(uint8_t, sock->outBuf, sock->outCount, sock->outCap);
laikaM_growarray(uint8_t, sock->outBuf, 1, sock->outCount, sock->outCap);
sock->outBuf[sock->outCount++] = data;
}
@@ -234,7 +234,7 @@ RAWSOCKCODE laikaS_rawRecv(struct sLaika_socket *sock, size_t sz, int *processed
int rcvd, start = sock->inCount;
/* make sure we have enough space to recv */
laikaM_growarray(uint8_t, sock->inBuf, sock->inCount + sz, sock->inCap);
laikaM_growarray(uint8_t, sock->inBuf, sz, sock->inCount, sock->inCap);
rcvd = recv(sock->sock, (buffer_t*)&sock->inBuf[sock->inCount], sz, LN_MSG_NOSIGNAL);
if (rcvd == 0) {