mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge remote-tracking branch 'upstream/master' into nTox-patches
This commit is contained in:
commit
81d4e4d2b8
|
@ -860,8 +860,8 @@ static void adjust_datasendspeed(Connection *connection, uint32_t req_packets)
|
|||
return;
|
||||
}
|
||||
|
||||
if (req_packets <= (connection->data_rate / connection->SYNC_rate) / 5 || req_packets <= 10) {
|
||||
connection->data_rate += (connection->data_rate / 8) + 1;
|
||||
if (req_packets <= (connection->data_rate / connection->SYNC_rate) / 4 || req_packets <= 10) {
|
||||
connection->data_rate += (connection->data_rate / 4) + 1;
|
||||
|
||||
if (connection->data_rate > connection->sendbuffer_length * connection->SYNC_rate)
|
||||
connection->data_rate = connection->sendbuffer_length * connection->SYNC_rate;
|
||||
|
|
|
@ -289,7 +289,7 @@ static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum)
|
|||
chat->group[peernum].last_pinged = unix_time();
|
||||
chat->group[peernum].pingid = contents.pingid;
|
||||
|
||||
return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents, sizeof(contents), 48);
|
||||
return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents, sizeof(contents), CRYPTO_PACKET_GROUP_CHAT_GET_NODES);
|
||||
}
|
||||
|
||||
static int send_sendnodes(Group_Chat *chat, IP_Port ip_port, int peernum, uint64_t pingid)
|
||||
|
@ -310,7 +310,7 @@ static int send_sendnodes(Group_Chat *chat, IP_Port ip_port, int peernum, uint64
|
|||
}
|
||||
|
||||
return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents,
|
||||
sizeof(contents.pingid) + sizeof(groupchat_nodes) * j, 49);
|
||||
sizeof(contents.pingid) + sizeof(groupchat_nodes) * j, CRYPTO_PACKET_GROUP_CHAT_SEND_NODES);
|
||||
}
|
||||
|
||||
static int handle_getnodes(Group_Chat *chat, IP_Port source, int peernum, uint8_t *data, uint32_t len)
|
||||
|
@ -414,21 +414,21 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
|
|||
uint16_t contents_len = len - GROUP_DATA_MIN_SIZE;
|
||||
|
||||
switch (data[crypto_box_PUBLICKEYBYTES + sizeof(message_num)]) {
|
||||
case 0: /* If message is ping */
|
||||
case GROUP_CHAT_PING: /* If message is ping */
|
||||
if (contents_len != 0)
|
||||
return 1;
|
||||
|
||||
chat->group[peernum].last_recv_msgping = unix_time();
|
||||
break;
|
||||
|
||||
case 16: /* If message is new peer */
|
||||
case GROUP_CHAT_NEW_PEER: /* If message is new peer */
|
||||
if (contents_len != crypto_box_PUBLICKEYBYTES)
|
||||
return 1;
|
||||
|
||||
addpeer(chat, contents);
|
||||
break;
|
||||
|
||||
case 64: /* If message is chat message */
|
||||
case GROUP_CHAT_CHAT_MESSAGE: /* If message is chat message */
|
||||
if (chat->group_message != NULL)
|
||||
(*chat->group_message)(chat, peernum, contents, contents_len, chat->group_message_userdata);
|
||||
|
||||
|
@ -441,7 +441,7 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
|
|||
}
|
||||
|
||||
if (handled == 1) {
|
||||
sendto_allpeers(chat, data, len, 50);
|
||||
sendto_allpeers(chat, data, len, CRYPTO_PACKET_GROUP_CHAT_BROADCAST);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -468,7 +468,7 @@ static uint8_t send_data(Group_Chat *chat, uint8_t *data, uint32_t len, uint8_t
|
|||
memcpy(packet + GROUP_DATA_MIN_SIZE, data, len);
|
||||
|
||||
packet[crypto_box_PUBLICKEYBYTES + sizeof(message_num)] = message_id;
|
||||
return sendto_allpeers(chat, packet, len + GROUP_DATA_MIN_SIZE, 50);
|
||||
return sendto_allpeers(chat, packet, len + GROUP_DATA_MIN_SIZE, CRYPTO_PACKET_GROUP_CHAT_BROADCAST);
|
||||
}
|
||||
/*
|
||||
* Handle get nodes group packet.
|
||||
|
@ -499,13 +499,13 @@ int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, ui
|
|||
return 1;
|
||||
|
||||
switch (number) {
|
||||
case 48:
|
||||
case CRYPTO_PACKET_GROUP_CHAT_GET_NODES:
|
||||
return handle_getnodes(chat, source, peernum, data, len);
|
||||
|
||||
case 49:
|
||||
case CRYPTO_PACKET_GROUP_CHAT_SEND_NODES:
|
||||
return handle_sendnodes(chat, source, peernum, data, len);
|
||||
|
||||
case 50:
|
||||
case CRYPTO_PACKET_GROUP_CHAT_BROADCAST:
|
||||
return handle_data(chat, data, len);
|
||||
|
||||
default:
|
||||
|
@ -517,13 +517,13 @@ int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, ui
|
|||
|
||||
uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length)
|
||||
{
|
||||
return send_data(chat, message, length, 64); //TODO: better return values?
|
||||
return send_data(chat, message, length, GROUP_CHAT_CHAT_MESSAGE); //TODO: better return values?
|
||||
}
|
||||
|
||||
uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id)
|
||||
{
|
||||
addpeer(chat, client_id);
|
||||
return send_data(chat, client_id, crypto_box_PUBLICKEYBYTES, 16); //TODO: better return values?
|
||||
return send_data(chat, client_id, crypto_box_PUBLICKEYBYTES, GROUP_CHAT_NEW_PEER); //TODO: better return values?
|
||||
}
|
||||
|
||||
void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *),
|
||||
|
@ -572,7 +572,7 @@ static void ping_close(Group_Chat *chat)
|
|||
static void ping_group(Group_Chat *chat)
|
||||
{
|
||||
if (is_timeout(chat->last_sent_ping, GROUP_PING_INTERVAL)) {
|
||||
if (send_data(chat, 0, 0, 0) != 0) /* Ping */
|
||||
if (send_data(chat, 0, 0, GROUP_CHAT_PING) != 0) /* Ping */
|
||||
chat->last_sent_ping = unix_time();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,10 @@ typedef struct Group_Chat {
|
|||
|
||||
} Group_Chat;
|
||||
|
||||
#define GROUP_CHAT_PING 0
|
||||
#define GROUP_CHAT_NEW_PEER 16
|
||||
#define GROUP_CHAT_CHAT_MESSAGE 64
|
||||
|
||||
/* Copy the name of peernum to name.
|
||||
* name must be at least MAX_NICK_BYTES long.
|
||||
*
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
|
||||
#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */
|
||||
#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */
|
||||
#define CRYPTO_PACKET_GROUP_CHAT_GET_NODES 48 /* Group chat get Nodes packet */
|
||||
#define CRYPTO_PACKET_GROUP_CHAT_SEND_NODES 49 /* Group chat send Nodes packet */
|
||||
#define CRYPTO_PACKET_GROUP_CHAT_BROADCAST 50 /* Group chat broadcast packet */
|
||||
#define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2)
|
||||
|
||||
#define CRYPTO_CONN_NO_CONNECTION 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user