Skip to content

Commit 9c51953

Browse files
committed
chore: Update golang binding with latest Messenger struct layout.
1 parent 4d08dc2 commit 9c51953

File tree

2 files changed

+75
-60
lines changed

2 files changed

+75
-60
lines changed

.clang-format

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
BasedOnStyle: WebKit
2+
ColumnLimit: 100
3+
PointerAlignment: Right
4+
SpacesBeforeTrailingComments: 2
5+
AlignConsecutiveMacros: true
6+
AlignEscapedNewlines: Left
7+
AlwaysBreakTemplateDeclarations: Yes
8+
SpaceBeforeCpp11BracedList: false
9+
Cpp11BracedListStyle: true
10+
11+
IncludeIsMainRegex: '([-_](test))?$'
12+
IncludeBlocks: Regroup
13+
IncludeCategories:
14+
- Regex: '^<.*\.h>'
15+
Priority: 1
16+
SortPriority: 0
17+
- Regex: '^<.*'
18+
Priority: 2
19+
SortPriority: 0
20+
- Regex: '.*'
21+
Priority: 3
22+
SortPriority: 0

group_intern.c

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
#include <time.h>
21
#include <stdio.h>
32
#include <stdlib.h>
43
#include <string.h>
4+
#include <time.h>
55
#include <tox/tox.h>
66

77
typedef union {
88
uint32_t uint32;
99
uint16_t uint16[2];
1010
uint8_t uint8[4];
11-
}
12-
IP4;
11+
} IP4;
1312

1413
extern const IP4 IP4_LOOPBACK;
1514
extern const IP4 IP4_BROADCAST;
@@ -19,8 +18,7 @@ typedef union {
1918
uint16_t uint16[8];
2019
uint32_t uint32[4];
2120
uint64_t uint64[2];
22-
}
23-
IP6;
21+
} IP6;
2422

2523
extern const IP6 IP6_LOOPBACK;
2624
extern const IP6 IP6_BROADCAST;
@@ -31,18 +29,16 @@ typedef struct {
3129
IP4 ip4;
3230
IP6 ip6;
3331
};
34-
}
35-
IP;
32+
} IP;
3633

3734
typedef struct {
3835
IP ip;
3936
uint16_t port;
40-
}
41-
IP_Port;
37+
} IP_Port;
4238

4339
typedef struct {
4440
IP_Port ip_port;
45-
uint8_t proxy_type; // a value from TCP_PROXY_TYPE
41+
uint8_t proxy_type; // a value from TCP_PROXY_TYPE
4642
} TCP_Proxy_Info;
4743

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

58-
/*logger_cb*/void *log_callback;
54+
/*logger_cb*/ void *log_callback;
5955
void *log_user_data;
6056
} Messenger_Options_Fake;
6157

62-
63-
#define MAX_RECEIVED_STORED 32
64-
#define CRYPTO_PUBLIC_KEY_SIZE 32
65-
#define CRYPTO_SHARED_KEY_SIZE 32
66-
#define CRYPTO_SYMMETRIC_KEY_SIZE CRYPTO_SHARED_KEY_SIZE
58+
#define MAX_RECEIVED_STORED 32
59+
#define CRYPTO_PUBLIC_KEY_SIZE 32
60+
#define CRYPTO_SHARED_KEY_SIZE 32
61+
#define CRYPTO_SYMMETRIC_KEY_SIZE CRYPTO_SHARED_KEY_SIZE
6762

6863
typedef struct {
69-
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
70-
IP_Port ip_port;
64+
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
65+
IP_Port ip_port;
7166
} Node_format_Fake;
7267

7368
#define DESIRED_CLOSE_CONNECTIONS 4
74-
#define MAX_GROUP_CONNECTIONS 16
75-
#define GROUP_IDENTIFIER_LENGTH (1 + CRYPTO_SYMMETRIC_KEY_SIZE) /* type + CRYPTO_SYMMETRIC_KEY_SIZE so we can use new_symmetric_key(...) to fill it */
69+
#define MAX_GROUP_CONNECTIONS 16
70+
#define GROUP_IDENTIFIER_LENGTH \
71+
(1 + CRYPTO_SYMMETRIC_KEY_SIZE) /* type + CRYPTO_SYMMETRIC_KEY_SIZE so we can \
72+
use new_symmetric_key(...) to fill it */
7673

7774
typedef struct {
7875
uint8_t status;
7976

80-
/*Group_Peer*/void *group;
77+
/*Group_Peer*/ void *group;
8178
uint32_t numpeers;
8279
#define MAX_GROUP_CONNECTIONS 16
8380
struct {
@@ -106,7 +103,8 @@ typedef struct {
106103

107104
uint64_t last_sent_ping;
108105

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

111109
void *object;
112110

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

118-
typedef enum {
119-
USERSTATUS_NONE,
120-
USERSTATUS_AWAY,
121-
USERSTATUS_BUSY,
122-
USERSTATUS_INVALID
123-
}
124-
USERSTATUS;
125-
116+
typedef enum { USERSTATUS_NONE, USERSTATUS_AWAY, USERSTATUS_BUSY, USERSTATUS_INVALID } USERSTATUS;
126117

127-
#define NUM_SAVED_TCP_RELAYS 8
118+
#define NUM_SAVED_TCP_RELAYS 8
128119
#define MAX_STATUSMESSAGE_LENGTH 1007
129120

130121
struct Messenger {
131122
/*Logger*/ void *log;
132123
/*Mono_Time*/ void *mono_time;
133124

134-
/*Networking_Core*/void *net;
135-
/*Net_Crypto*/void *net_crypto;
136-
/*DHT*/void *dht;
125+
/*Networking_Core*/ void *net;
126+
/*Net_Crypto*/ void *net_crypto;
127+
/*DHT*/ void *dht;
137128

138-
/*Onion*/void *onion;
139-
/*Onion_Announce*/void *onion_a;
140-
/*Onion_Client*/void *onion_c;
129+
/*Onion*/ void *onion;
130+
/*Onion_Announce*/ void *onion_a;
131+
/*Onion_Client*/ void *onion_c;
141132

142-
/*Friend_Connections*/void *fr_c;
133+
/*Friend_Connections*/ void *fr_c;
143134

144-
/*TCP_Server*/void *tcp_server;
145-
/*Friend_Requests **/void *fr;
135+
/*TCP_Server*/ void *tcp_server;
136+
/*Friend_Requests **/ void *fr;
146137
uint8_t name[TOX_MAX_NAME_LENGTH];
147138
uint16_t name_length;
148139

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

152143
USERSTATUS userstatus;
153144

154-
/*Friend*/void *friendlist;
145+
/*Friend*/ void *friendlist;
155146
uint32_t numfriends;
156147

157148
time_t lastdump;
158149

159-
uint8_t has_added_relays; // If the first connection has occurred in do_messenger
160-
Node_format_Fake loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
150+
uint8_t has_added_relays; // If the first connection has occurred in do_messenger
151+
Node_format_Fake loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
161152

162-
void (*friend_message)(struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *);
153+
void (*friend_request)(
154+
struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *);
155+
void (*friend_message)(
156+
struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *);
163157
void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
164-
void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
158+
void (*friend_statusmessagechange)(
159+
struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
165160
void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
166161
void (*friend_typingchange)(struct Messenger *m, uint32_t, bool, void *);
167162
void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *);
@@ -172,10 +167,11 @@ struct Messenger {
172167
void *conferences_object; /* Set by new_groupchats()*/
173168
void (*conference_invite)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
174169

175-
void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t,
176-
void *);
170+
void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t,
171+
const uint8_t *, size_t, void *);
177172
void (*file_filecontrol)(struct Messenger *m, uint32_t, uint32_t, unsigned int, void *);
178-
void (*file_filedata)(struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
173+
void (*file_filedata)(
174+
struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
179175
void (*file_reqchunk)(struct Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);
180176

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

193189
typedef struct {
194-
/*Messenger*/void *m;
195-
/*Friend_Connections*/void *fr_c;
190+
/*Messenger*/ void *m;
191+
/*Friend_Connections*/ void *fr_c;
196192

197193
Group_c_Fake *chats;
198194
uint32_t num_chats;
199195
} Group_Chats;
200196

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

203-
enum {
204-
GROUPCHAT_STATUS_NONE,
205-
GROUPCHAT_STATUS_VALID,
206-
GROUPCHAT_STATUS_CONNECTED
207-
};
199+
enum { GROUPCHAT_STATUS_NONE, GROUPCHAT_STATUS_VALID, GROUPCHAT_STATUS_CONNECTED };
208200

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

236-
char **p = (char**)(&((char*)*(struct Messenger **)tox)[0] + conferences_object_offset);
228+
char **p = (char **)(&((char *)*(struct Messenger **)tox)[0] + conferences_object_offset);
237229
// void *p2 = ((struct Messenger*)tox)->conferences_object;
238-
Group_Chats* grpchats = (Group_Chats*)(*p);
230+
Group_Chats *grpchats = (Group_Chats *)(*p);
239231
if (groupnumber_not_valid(grpchats, groupnumber)) {
240232
return 0;
241233
}
242234
Group_c_Fake *g = &grpchats->chats[groupnumber];
243235
return g;
244236
}
245237

246-
void tox_conference_get_identifier(Tox *tox, uint32_t conference_number, void *idbuf) {
238+
void tox_conference_get_identifier(Tox *tox, uint32_t conference_number, void *idbuf)
239+
{
247240
Group_c_Fake *g = get_group_c(tox, conference_number);
248241
if (g) {
249242
memcpy(idbuf, g->identifier, GROUP_IDENTIFIER_LENGTH);
250243
}
251244
}
252-
void tox_conference_get_pubkey(Tox *tox, uint32_t conference_number, void *pkbuf) {
245+
void tox_conference_get_pubkey(Tox *tox, uint32_t conference_number, void *pkbuf)
246+
{
253247
Group_c_Fake *g = get_group_c(tox, conference_number);
254248
if (g) {
255249
memcpy(pkbuf, g->real_pk, CRYPTO_PUBLIC_KEY_SIZE);
256250
}
257251
}
258-

0 commit comments

Comments
 (0)