Skip to content

Commit

Permalink
chore: Update golang binding with latest Messenger struct layout.
Browse files Browse the repository at this point in the history
iphydf committed Feb 23, 2022

Verified

This commit was signed with the committer’s verified signature.
1 parent 4d08dc2 commit 9c51953
Showing 2 changed files with 75 additions and 60 deletions.
22 changes: 22 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BasedOnStyle: WebKit
ColumnLimit: 100
PointerAlignment: Right
SpacesBeforeTrailingComments: 2
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlwaysBreakTemplateDeclarations: Yes
SpaceBeforeCpp11BracedList: false
Cpp11BracedListStyle: true

IncludeIsMainRegex: '([-_](test))?$'
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
- Regex: '^<.*'
Priority: 2
SortPriority: 0
- Regex: '.*'
Priority: 3
SortPriority: 0
113 changes: 53 additions & 60 deletions group_intern.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <tox/tox.h>

typedef union {
uint32_t uint32;
uint16_t uint16[2];
uint8_t uint8[4];
}
IP4;
} IP4;

extern const IP4 IP4_LOOPBACK;
extern const IP4 IP4_BROADCAST;
@@ -19,8 +18,7 @@ typedef union {
uint16_t uint16[8];
uint32_t uint32[4];
uint64_t uint64[2];
}
IP6;
} IP6;

extern const IP6 IP6_LOOPBACK;
extern const IP6 IP6_BROADCAST;
@@ -31,18 +29,16 @@ typedef struct {
IP4 ip4;
IP6 ip6;
};
}
IP;
} IP;

typedef struct {
IP ip;
uint16_t port;
}
IP_Port;
} IP_Port;

typedef struct {
IP_Port ip_port;
uint8_t proxy_type; // a value from TCP_PROXY_TYPE
uint8_t proxy_type; // a value from TCP_PROXY_TYPE
} TCP_Proxy_Info;

typedef struct {
@@ -55,29 +51,30 @@ typedef struct {
uint8_t hole_punching_enabled;
bool local_discovery_enabled;

/*logger_cb*/void *log_callback;
/*logger_cb*/ void *log_callback;
void *log_user_data;
} Messenger_Options_Fake;


#define MAX_RECEIVED_STORED 32
#define CRYPTO_PUBLIC_KEY_SIZE 32
#define CRYPTO_SHARED_KEY_SIZE 32
#define CRYPTO_SYMMETRIC_KEY_SIZE CRYPTO_SHARED_KEY_SIZE
#define MAX_RECEIVED_STORED 32
#define CRYPTO_PUBLIC_KEY_SIZE 32
#define CRYPTO_SHARED_KEY_SIZE 32
#define CRYPTO_SYMMETRIC_KEY_SIZE CRYPTO_SHARED_KEY_SIZE

typedef struct {
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
IP_Port ip_port;
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
IP_Port ip_port;
} Node_format_Fake;

#define DESIRED_CLOSE_CONNECTIONS 4
#define MAX_GROUP_CONNECTIONS 16
#define GROUP_IDENTIFIER_LENGTH (1 + CRYPTO_SYMMETRIC_KEY_SIZE) /* type + CRYPTO_SYMMETRIC_KEY_SIZE so we can use new_symmetric_key(...) to fill it */
#define MAX_GROUP_CONNECTIONS 16
#define GROUP_IDENTIFIER_LENGTH \
(1 + CRYPTO_SYMMETRIC_KEY_SIZE) /* type + CRYPTO_SYMMETRIC_KEY_SIZE so we can \
use new_symmetric_key(...) to fill it */

typedef struct {
uint8_t status;

/*Group_Peer*/void *group;
/*Group_Peer*/ void *group;
uint32_t numpeers;
#define MAX_GROUP_CONNECTIONS 16
struct {
@@ -106,7 +103,8 @@ typedef struct {

uint64_t last_sent_ping;

int number_joined; /* friendcon_id of person that invited us to the chat. (-1 means none) */
/* friendcon_id of person that invited us to the chat. (-1 means none) */
int number_joined;

void *object;

@@ -115,34 +113,27 @@ typedef struct {
void (*group_on_delete)(void *, uint32_t);
} Group_c_Fake;

typedef enum {
USERSTATUS_NONE,
USERSTATUS_AWAY,
USERSTATUS_BUSY,
USERSTATUS_INVALID
}
USERSTATUS;

typedef enum { USERSTATUS_NONE, USERSTATUS_AWAY, USERSTATUS_BUSY, USERSTATUS_INVALID } USERSTATUS;

#define NUM_SAVED_TCP_RELAYS 8
#define NUM_SAVED_TCP_RELAYS 8
#define MAX_STATUSMESSAGE_LENGTH 1007

struct Messenger {
/*Logger*/ void *log;
/*Mono_Time*/ void *mono_time;

/*Networking_Core*/void *net;
/*Net_Crypto*/void *net_crypto;
/*DHT*/void *dht;
/*Networking_Core*/ void *net;
/*Net_Crypto*/ void *net_crypto;
/*DHT*/ void *dht;

/*Onion*/void *onion;
/*Onion_Announce*/void *onion_a;
/*Onion_Client*/void *onion_c;
/*Onion*/ void *onion;
/*Onion_Announce*/ void *onion_a;
/*Onion_Client*/ void *onion_c;

/*Friend_Connections*/void *fr_c;
/*Friend_Connections*/ void *fr_c;

/*TCP_Server*/void *tcp_server;
/*Friend_Requests **/void *fr;
/*TCP_Server*/ void *tcp_server;
/*Friend_Requests **/ void *fr;
uint8_t name[TOX_MAX_NAME_LENGTH];
uint16_t name_length;

@@ -151,17 +142,21 @@ struct Messenger {

USERSTATUS userstatus;

/*Friend*/void *friendlist;
/*Friend*/ void *friendlist;
uint32_t numfriends;

time_t lastdump;

uint8_t has_added_relays; // If the first connection has occurred in do_messenger
Node_format_Fake loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
uint8_t has_added_relays; // If the first connection has occurred in do_messenger
Node_format_Fake loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config

void (*friend_message)(struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *);
void (*friend_request)(
struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *);
void (*friend_message)(
struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *);
void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
void (*friend_statusmessagechange)(
struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
void (*friend_typingchange)(struct Messenger *m, uint32_t, bool, void *);
void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *);
@@ -172,10 +167,11 @@ struct Messenger {
void *conferences_object; /* Set by new_groupchats()*/
void (*conference_invite)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);

void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t,
void *);
void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t,
const uint8_t *, size_t, void *);
void (*file_filecontrol)(struct Messenger *m, uint32_t, uint32_t, unsigned int, void *);
void (*file_filedata)(struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
void (*file_filedata)(
struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
void (*file_reqchunk)(struct Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);

void (*msi_packet)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
@@ -191,20 +187,16 @@ struct Messenger {
};

typedef struct {
/*Messenger*/void *m;
/*Friend_Connections*/void *fr_c;
/*Messenger*/ void *m;
/*Friend_Connections*/ void *fr_c;

Group_c_Fake *chats;
uint32_t num_chats;
} Group_Chats;

extern void *group_get_object(/*const Group_Chats*/ void *g_c, uint32_t groupnumber);

enum {
GROUPCHAT_STATUS_NONE,
GROUPCHAT_STATUS_VALID,
GROUPCHAT_STATUS_CONNECTED
};
enum { GROUPCHAT_STATUS_NONE, GROUPCHAT_STATUS_VALID, GROUPCHAT_STATUS_CONNECTED };

/* return 1 if the groupnumber is not valid.
* return 0 if the groupnumber is valid.
@@ -233,26 +225,27 @@ static Group_c_Fake *get_group_c(Tox *tox, int groupnumber)
// int fos2 = offsetof(Group_c_Fake, identifier);
int conferences_object_offset = fos;

char **p = (char**)(&((char*)*(struct Messenger **)tox)[0] + conferences_object_offset);
char **p = (char **)(&((char *)*(struct Messenger **)tox)[0] + conferences_object_offset);
// void *p2 = ((struct Messenger*)tox)->conferences_object;
Group_Chats* grpchats = (Group_Chats*)(*p);
Group_Chats *grpchats = (Group_Chats *)(*p);
if (groupnumber_not_valid(grpchats, groupnumber)) {
return 0;
}
Group_c_Fake *g = &grpchats->chats[groupnumber];
return g;
}

void tox_conference_get_identifier(Tox *tox, uint32_t conference_number, void *idbuf) {
void tox_conference_get_identifier(Tox *tox, uint32_t conference_number, void *idbuf)
{
Group_c_Fake *g = get_group_c(tox, conference_number);
if (g) {
memcpy(idbuf, g->identifier, GROUP_IDENTIFIER_LENGTH);
}
}
void tox_conference_get_pubkey(Tox *tox, uint32_t conference_number, void *pkbuf) {
void tox_conference_get_pubkey(Tox *tox, uint32_t conference_number, void *pkbuf)
{
Group_c_Fake *g = get_group_c(tox, conference_number);
if (g) {
memcpy(pkbuf, g->real_pk, CRYPTO_PUBLIC_KEY_SIZE);
}
}

0 comments on commit 9c51953

Please sign in to comment.