bittorrent old code cleanup. Enlarged BT cache

This commit is contained in:
Luca Deri
2021-11-16 10:05:18 +01:00
parent f2a279e441
commit a6545ea095
2 changed files with 9 additions and 41 deletions
+5 -39
View File
@@ -502,37 +502,6 @@ typedef struct atomic {
volatile int counter;
} atomic_t;
struct hash_ip4p_node {
struct hash_ip4p_node *next,*prev;
time_t lchg;
u_int16_t port,count:12,flag:4;
u_int32_t ip;
// + 12 bytes for ipv6
};
struct hash_ip4p {
struct hash_ip4p_node *top;
spinlock_t lock;
size_t len;
};
struct hash_ip4p_table {
size_t size;
int ipv6;
spinlock_t lock;
atomic_t count;
struct hash_ip4p tbl;
};
struct bt_announce { // 192 bytes
u_int32_t hash[5];
u_int32_t ip[4];
u_int32_t time;
u_int16_t port;
u_int8_t name_len,
name[192 - 4*10 - 2 - 1]; // 149 bytes
};
/* NDPI_PROTOCOL_TINC */
#define TINC_CACHE_MAX_SIZE 10
@@ -1117,12 +1086,6 @@ struct ndpi_detection_module_struct {
u_int32_t jabber_stun_timeout;
u_int32_t jabber_file_transfer_timeout;
u_int8_t ip_version_limit;
/* NDPI_PROTOCOL_BITTORRENT */
struct hash_ip4p_table *bt_ht, *bt6_ht;
/* BT_ANNOUNCE */
struct bt_announce *bt_ann;
int bt_ann_len;
/* NDPI_PROTOCOL_OOKLA */
struct ndpi_lru_cache *ookla_cache;
@@ -1274,6 +1237,10 @@ struct ndpi_flow_struct {
u_int8_t auth_found:1, auth_failed:1, auth_tls:1, auth_done:1, _pad:4;
char username[32], password[16];
} ftp_imap_pop_smtp;
struct {
u_int8_t bt_check_performed;
} bittorrent;
union {
/* the only fields useful for nDPI and ntopng */
@@ -1296,8 +1263,7 @@ struct ndpi_flow_struct {
char ssl_version_str[12];
u_int16_t ssl_version, server_names_len;
char client_requested_server_name[256]; /* SNI hostname length: RFC 4366 */
char
*server_names, *alpn, *tls_supported_versions, *issuerDN, *subjectDN;
char *server_names, *alpn, *tls_supported_versions, *issuerDN, *subjectDN;
u_int32_t notBefore, notAfter;
char ja3_client[33], ja3_server[33];
u_int16_t server_cipher;
+4 -2
View File
@@ -85,7 +85,7 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_UNKNOWN);
if(ndpi_struct->bittorrent_cache == NULL)
ndpi_struct->bittorrent_cache = ndpi_lru_cache_init(1024);
ndpi_struct->bittorrent_cache = ndpi_lru_cache_init(8192);
if(ndpi_struct->bittorrent_cache && packet->iph) {
u_int32_t key1, key2;
@@ -431,11 +431,13 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) {
/* check for tcp retransmission here */
if((flow->packet_counter <= 1 /* Do the check once */) && ndpi_struct->bittorrent_cache) {
if((!flow->bittorrent.bt_check_performed /* Do the check once */) && ndpi_struct->bittorrent_cache) {
u_int16_t cached_proto;
u_int8_t found = 0;
u_int32_t key1, key2;
flow->bittorrent.bt_check_performed = 1;
/* Check cached communications */
if(packet->udp)
key1 = packet->iph->saddr + packet->udp->source, key2 = packet->iph->daddr + packet->udp->dest;