-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsnp.h
1138 lines (893 loc) · 26.9 KB
/
dsnp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2008-2011, Adrian Thurston <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _DSNPD_H
#define _DSNPD_H
#include <mysql/mysql.h>
#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/ssl.h>
#include <vector>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include "string.h"
#include "buffer.h"
#include "parser.h"
#include "dlist.h"
#include "recipients.h"
#define DSNPD_LOG_FILE LOGDIR "/dsnpd.log"
#define DSNPK_LOG_FILE LOGDIR "/dsnpk.log"
#define NOTIF_LOG_FILE LOGDIR "/dsnpn.log"
/* Types of things should never be zero. */
#define INVALID_THING 0
#define REL_TYPE_SELF 1
#define REL_TYPE_FRIEND 8
#define NET_TYPE_PRIMARY 1
#define NET_TYPE_GROUP 2
#define RELID_PREFRIEND 20
#define RELID_MESSAGE 21
#define ACTOR_TYPE_PUBLISHER 70
#define ACTOR_TYPE_AUTHOR 71
#define ACTOR_TYPE_SUBJECT 72
/* For subjects we can go right into completed. But for author we need to go
* into returned once it comes back and complete only in the final step
* controlled by the browser. */
#define ACTOR_STATE_PENDING 90
#define ACTOR_STATE_RETURNED 91
#define ACTOR_STATE_COMPLETE 92
#define RB_REQ_STATE_PENDING 40
#define RB_REQ_STATE_COMPLETE 41
#define RB_RSP_STATE_PENDING 50
#define RB_RSP_STATE_COMPLETE 51
#define NUM_KEY_PRIVS 5
#define KEY_PRIV0 0L
#define KEY_PRIV1 1L
#define KEY_PRIV2 2L
#define KEY_PRIV3 3L
#define KEY_PRIV4 4L
#define RELID_SIZE 16
#define REQID_SIZE 16
#define TOKEN_SIZE 16
#define SK_SIZE 16
#define SK_SIZE_HEX 33
#define SALT_SIZE 18
#define MAX_BRD_PHOTO_SIZE 16384
// --VERSION--
#define VERSION_MASK_0_1 0x01
#define VERSION_MASK_0_2 0x02
#define VERSION_MASK_0_3 0x04
#define VERSION_MASK_0_4 0x08
#define VERSION_MASK_0_5 0x10
#define VERSION_MASK_0_6 0x20
#define DAEMON_DAEMON_TIMEOUT 7
#define DSNPD_CONF SYSCONFDIR "/dsnpd.conf"
/* Barrier commands. */
#define BA_QUIT 11
/* Agent control commands */
#define AC_SOCKET 60
#define AC_LOG_FD 61
#define AC_QUIT 62
#define CHECK_PASS_OK 1
#define CHECK_PASS_BAD_USER 2
#define CHECK_PASS_BAD_PASS 3
#define FC_SENT 40L
#define FC_GRANTED_ACCEPT 41L
#define FC_RECEIVED 42L
#define FC_ESTABLISHED 43L
struct BioWrapParse;
struct TlsConnect;
struct Server;
struct Broadcast;
/* There are a number of SSL context's necessary. There must be a server
* context for each site that contains the appropriate keys. There can be only
* one client context, which contains the loaded list of trusted CA certs. */
struct TlsContext
{
/* Indexed by configuration id. */
std::vector<SSL_CTX*> clientCtx;
std::vector<SSL_CTX*> serverCtx;
};
struct ConfigSection;
struct Config;
struct ConfigCtx
{
ConfigCtx( Config *c ) : c(c) {}
MYSQL *dbConnect( const String &host, const String &database,
const String &user, const String &pass );
MYSQL *dbConnect();
Config *c;
};
/* Wraps up RSA struct and private key/x509. Useful for transition to CMS. */
struct Keys
{
RSA *rsa;
};
struct User
{
struct ByLoginToken {};
User( MYSQL *mysql, ByLoginToken, const char *loginToken );
User( MYSQL *mysql, const char *user );
User( MYSQL *mysql, long long _id );
long long id();
MYSQL *mysql;
String iduri;
long long siteId();
Allocated site();
bool haveId;
long long _id;
};
struct Site
{
struct ByLoginToken {};
Site( MYSQL *mysql, const char *_site );
Site( MYSQL *mysql, long long _id );
long long id();
MYSQL *mysql;
String site;
bool haveId;
long long _id;
};
struct Identity
{
struct ByHash {};
Identity( MYSQL *mysql, const char *iduri );
Identity( MYSQL *mysql, ByHash, const char *hash );
Identity( MYSQL *mysql, long long _id );
Identity( long long _id, const char *iduri );
MYSQL *mysql;
String iduri;
long long id();
Allocated hash();
bool publicKey();
const char *host();
private:
long parse();
String _host;
bool haveId, havePublicKey, parsed;
long long _id;
bool _publicKey;
};
struct FriendClaim
{
struct ByFloginToken {};
FriendClaim( MYSQL *mysql, User &user, Identity &identity );
FriendClaim( MYSQL *mysql, const char *getRelid );
FriendClaim( MYSQL *mysql, ByFloginToken, const char *floginToken );
MYSQL *mysql;
void loadRelids();
long long id;
long long userId;
long long identityId;
int state;
String putRelids[NUM_KEY_PRIVS];
String getRelids[NUM_KEY_PRIVS];
};
struct BioWrap
{
enum Type
{
Null = 1,
Server,
Local,
};
BioWrap( Type type );
Type type;
int sockFd;
BIO *sockBio;
/* Sending. */
int printf( const char *fmt, ... );
void write( const char *msg, long mLen );
void write( const String &msg )
{ write( msg.data, msg.length ); }
void writeBody( const String &msg );
void returnOkLocal();
void returnOkLocal( const String &r1 );
void returnOkLocal( const String &r1, const String &r2 );
void returnOkLocal( const String &r1, const String &r2, long ld3 );
void returnOkLocal( const String &r1, const String &r2, const String &r3 );
void returnOkServer();
void returnOkServer( const String &r1 );
void returnError( int errorCode );
void returnError( int errorCode, int arg1 );
void returnError( int errorCode, int arg1, int arg2 );
void returnError( int errorCode, const char *arg1 );
void returnError( int errorCode, const char *arg1, const char *arg2 );
};
struct BioWrapParse
:
public ConfigCtx,
public BioWrap
{
BioWrapParse( Config *c, BioWrap::Type type, TlsContext &tlsContext );
~BioWrapParse();
void setSockFd( int sfd );
TlsContext &tlsContext;
String result;
const long linelen;
char *input;
void makeNonBlocking();
void makeNonBlocking( int fd );
template <class Func, class Throw> void nonBlockingSslFunc( SSL *ssl );
/* Receiving. */
int readParse( Parser &parser );
void sslError( int e );
void sslStartServer();
void startTls();
};
struct TlsConnect
:
public BioWrapParse
{
/* This is always a server-server BIO wrap. */
TlsConnect( Config *c, TlsContext &tlsContext )
:
BioWrapParse( c, BioWrap::Server, tlsContext )
{}
void connect( const String &host );
private:
void sslStartClient( const String &host );
void openInetConnection( const String &host, unsigned short port );
};
enum ConfigSlice
{
SliceDaemon = 1,
SliceKeyAgent,
SliceNotifAgent
};
struct ConfigVar
{
const char *name;
ConfigSlice slice;
};
struct ConfigSection
{
ConfigSection( int id )
: id(id) {}
/* Main sections. */
String CFG_PORT;
String CFG_DB_HOST;
String CFG_DB_USER;
String CFG_DB_DATABASE;
String CFG_DB_PASS;
String CFG_KEYS_HOST;
String CFG_KEYS_USER;
String CFG_KEYS_DATABASE;
String CFG_KEYS_PASS;
String CFG_NOTIF_HOST;
String CFG_NOTIF_KEYS_USER;
String CFG_NOTIF_DATABASE;
String CFG_NOTIF_PASS;
/* Host sections. */
String CFG_HOST;
String CFG_TLS_CRT;
String CFG_TLS_KEY;
/* Site sections. */
String CFG_NOTIFICATION;
String CFG_COMM_KEY;
/* Name is given in the config. Id is allocated. */
String name;
int id;
ConfigSection *prev, *next;
};
struct ConfigList
: public DList<ConfigSection>
{
};
struct Config
{
Config()
: main(0), host(0), site(0) {}
/* The main config section from the file. */
ConfigSection *main;
/* List of hosts and sites. */
ConfigList hostList;
ConfigList siteList;
/* The selected host and site. */
ConfigSection *host;
ConfigSection *site;
void selectHostByHostName( const String &hostName );
void selectSiteByCommKey( const String &key );
void selectSiteByName( const String &site );
};
struct ConfigParser
{
ConfigParser( const char *confFile, ConfigSlice requestedSlice, Config *config );
void setValue( int i, const String &value );
void init();
void parseData( const char *data, long length );
void startHost();
void startSite();
void processValue();
String name, value;
Buffer buf;
int cs;
/* output. */
Config *config;
/* Parsing context. */
ConfigSection *curSect;
int nextConfigSectionId;
ConfigSlice requestedSlice;
static ConfigVar varNames[];
};
struct PutKey
{
PutKey( MYSQL *mysql, long long netorkId );
String distName;
long long generation;
long long id;
};
void fatal( const char *fmt, ... );
void error( const char *fmt, ... );
void warning( const char *fmt, ... );
void message( const char *fmt, ... );
void _dsnpd_debug( long realm, const char *fmt, ... );
int openLogFile( const char *fn );
void openLogFile();
void setLogFd( int fd );
void logToConsole( int fd );
#define DBG_FDT 0x0001
#define DBG_PROC 0x0002
#define DBG_EP 0x0004
#define DBG_PRIV 0x0008
#define DBG_NOTIF 0x0010
#define DBG_CFG 0x0020
#define DBG_QUEUE 0x0040
#if ENABLE_DEBUG
#define debug( realm, ... ) _dsnpd_debug( realm, __VA_ARGS__ )
#else
#define debug( realm, ... )
#endif
/*
* Conversion
*/
Allocated base64ToBin( const char *src, long srcLen );
inline Allocated base64ToBin( const String &src ) { return base64ToBin( src(), src.length ); }
Allocated binToBase64( const u_char *data, long len );
inline Allocated binToBase64( const String &src ) { return binToBase64( src.binary(), src.length ); }
Allocated bnToBase64( const BIGNUM *n );
Allocated bnToBin( const BIGNUM *n );
char *bin2hex( unsigned char *data, long len );
long hex2bin( unsigned char *dest, long len, const char *src );
Allocated passHash( const u_char *pass_salt, const char *pass );
BIGNUM *base64ToBn( const char *base64 );
BIGNUM *binToBn( const String &bin );
struct DbQuery
{
struct Log {};
DbQuery( MYSQL *mysql, const char *fmt, ... );
DbQuery( Log, MYSQL *mysql, const char *fmt, ... );
~DbQuery();
MYSQL_ROW fetchRow()
{ return mysql_fetch_row( result ); }
u_long *fetchLengths()
{ return mysql_fetch_lengths( result ); }
long rows()
{ return mysql_num_rows( result ); }
long affectedRows()
{ return mysql_affected_rows( mysql ); }
void seek( unsigned long long offset )
{ mysql_data_seek( result, offset ); }
void free();
MYSQL *mysql;
MYSQL_RES *result;
};
long long lastInsertId( MYSQL *mysql );
struct ServerParser
:
public Parser
{
ServerParser( Server *server );
virtual Parser::Control data( const char *data, int dlen );
long cs;
String user, pass, email, iduri;
String reqid;
String hash, key, relid, token;
String distName;
String sessionId;
String loginToken, floginToken;
long length, counter;
long long generation;
int retVal;
RecipientList recipientList;
Buffer buf;
String body;
String host;
MYSQL *mysql;
bool tls;
bool exit;
long v, versions;
u_long val;
u_char *dest;
Server *server;
};
struct CommandParser
:
public Parser
{
CommandParser( Server *server );
virtual Parser::Control data( const char *data, int dlen );
long cs;
String user, pass, email, iduri;
String reqid;
String hash, key, relid, token;
String distName, privateName;
String sessionId;
String loginToken, floginToken;
long length, counter;
long long generation;
int retVal;
RecipientList recipientList;
Buffer buf;
String body;
String host;
MYSQL *mysql;
bool tls;
bool exit;
long v, versions;
u_long val;
u_char *dest;
Server *server;
};
struct UserMessageParser
:
public Parser
{
UserMessageParser( const String &msg )
{
parse( msg );
}
long cs;
Buffer buf;
String messageId;
String publisher;
String author;
SubjectList subjects;
virtual Control data( const char *data, int dlen );
};
struct ResponseParser
:
public Parser
{
ResponseParser();
virtual Parser::Control data( const char *data, int dlen );
int cs;
bool OK;
Buffer buf;
String body;
int length, counter;
u_long val;
u_char *dest;
};
struct MessageParser
:
public Parser
{
enum Type
{
Unknown = 1,
BroadcastKey,
RemoteBroadcastKey,
EncryptRemoteBroadcastAuthor,
EncryptRemoteBroadcastSubject,
ReturnRemoteBroadcastAuthor,
ReturnRemoteBroadcastSubject,
BroadcastSuccessAuthor,
BroadcastSuccessSubject,
UserMessage,
RepubRemoteBroadcastPublisher,
RepubRemoteBroadcastAuthor,
RepubRemoteBroadcastSubject,
};
long cs;
Buffer buf;
Type type;
String messageId;
String iduri, relid;
String token, reqid, hash;
String distName;
long length, counter, number;
long long generation;
String body;
String recipients;
u_long val;
u_char *dest;
virtual Control data( const char *data, int dlen );
};
struct FofMessageParser
:
public Parser
{
enum Type
{
Unknown = 1,
RbBroadcastKey,
};
long cs;
Buffer buf;
Type type;
long length, counter;
String body;
String hash;
virtual Control data( const char *data, int dlen );
};
struct PrefriendParser
:
public Parser
{
enum Type
{
Unknown = 1,
NotifyAccept,
Registered
};
long cs;
Buffer buf;
long counter;
u_long val;
u_char *dest;
Type type;
String peerNotifyReqid;
String friendClaimSigKey;
virtual Control data( const char *data, int dlen );
};
struct Barrier
{
Barrier( int fd )
: fd(fd) {}
char readCommand();
void command( char cmd );
void quit();
char readChar();
int readInt();
void readData( String &s );
long long readLongLong();
void writeLongLong( long long ll );
void writeChar( char c );
void writeInt( int i );
void writeData( const String &s );
int fd;
};
struct NotifService
:
public ConfigCtx,
public Barrier
{
NotifService( Config *c, int fd )
:
ConfigCtx(c),
Barrier(fd)
{}
int service();
void recvConfig();
char *const* makeNotifiyArgv();
void recvNotification();
void execNotification( int stdinFd, int stdoutFd, int stderrFd );
void sendArgsBody( int fd, const String &site, const String &args, const String &body );
void waitNotification( pid_t pid );
FILE *wrapPipeFd( int fd, const char *mode );
int readResult( int fd );
void writeNotif( int fd, const char *data, long dlen );
};
struct NotifAgent
: public Barrier
{
NotifAgent( int fd )
:
Barrier(fd)
{}
void appNotification( const String &site, const String &args );
void appNotification( const String &site, const String &args, const String &body );
void notifNewUser( const String &site, const String &iduri,
const String &hash, const String &distName );
void notifLogout( const String &site, const char *sessionId );
void notifFriendRequestSent( const String &site, const char *user, const char *iuduri,
const char *hash, const char *userNotifyReqid );
void notifFriendRequestReceived( const String &site, const char *user,
const char *iduri, const char *hash, const char *acceptReqid );
void notifFriendRequestAccepted( const String &site, const char *user,
const char *iduri, const char *acceptReqid );
void notifSentFriendRequestAccepted( const String &site, const char *user,
const char *iduri, const char *userNotifyReqid );
void notifMessage( const String &site, const char *user, const char *friendId,
const String &msg );
void notifBroadcast( const String &site, const char *user,
const char *broadcaster, const String &msg );
};
struct KeyAgent;
struct Server
:
public ConfigCtx
{
Server( Config *c, TlsContext &tlsContext, KeyAgent &keyAgent, NotifAgent ¬ifAgent )
:
ConfigCtx(c),
tlsContext(tlsContext),
bioWrap(c, BioWrap::Server, tlsContext),
keyAgent(keyAgent),
notifAgent(notifAgent),
mysql(0)
{}
TlsContext &tlsContext;
BioWrapParse bioWrap;
KeyAgent &keyAgent;
NotifAgent ¬ifAgent;
bool deliverBroadcast();
void runServerBare( int sockFd );
void runServer( int sockFd );
void runReceivedQueueBare();
void runReceivedQueue();
void runCommandBare();
int runCommand();
void negotiation( long versions, bool tls, const String &host, const String &key );
void broadcastReceipient( RecipientList &recipients, const String &relid );
void acceptFriend( const String &token, const String &reqid );
void receiveBroadcastList( RecipientList &recipientList, const String &distName,
long long keyGen, const String &msg );
void fetchFtoken( const String &reqid );
void fetchRequestedRelid( const String &reqid );
void fetchResponseRelid( const String &reqid );
void friendFinal( const String &user, const String &reqid, const String &iduri );
void login( const String &user, const String &pass, const String &sessionId );
void ftokenRequest( const String &user, const String &hash );
void ftokenResponse( const String &user, const String &hash,
const String &reqid );
void submitFtoken( const String &token, const String &sessionId );
void receiveMessageEstablished( FriendClaim &friendClaim, const String &relid, const String &msg );
void receiveMessage( const String &relid, const String &msg );
void receiveFofMessage( const String &relid, const String &msg );
void newUser( const String &iduri, const String &privateName, const String &pass );
void recieveMessagePrefriend( FriendClaim &claim, const String &relid, const String &msg );
void publicKey( const String &identity );
void relidRequest( const String &user, const String &iduri );
void relidResponse( const String &token, const String &reqid,
const String &identity );
void submitBroadcast( const String &floginToken, const String &msg );
void remoteBroadcastRequest( const String &floginToken, const String &msg );
void remoteBroadcastResponse( const String &loginToken, const String &reqid );
void remoteBroadcastFinal( const String &floginToken, const String &reqid );
bool verifyBroadcast( User &user, Identity &broadcaster, Broadcast &b );
Allocated createRbRequestActor( long long remoteBroadcastRequestId,
int state, int type, long long identityId );
void submitMessage( const String &user, const String &iduri, const String &msg );
bool haveRbSigKey( const String &rbSigKeyHash );
private:
void checkRemoteBroadcastComplete( User &user, long long remoteBroadcastRequestId );
void verifyRemoteBroadcast( Identity &publisherId, Identity &authorId,
UserMessageParser &msgParser );
long long storeGetRelid( User &user, Identity &identity,
long long friendClaimId, int keyPriv, const String &relid );
long long storePutRelid( User &user, Identity &identity,
long long friendClaimId, int keyPriv, const String &relid );
void encryptRemoteBroadcastAuthor( User &user, Identity &publisherId,
FriendClaim &friendClaim, const String &reqid, const String &token,
const String &network, long long generation, const String &recipients,
const String &plainMsg );
void encryptRemoteBroadcastSubject( User &user, Identity &publisherId,
FriendClaim &friendClaim, const String &reqid, const String &token,
const String &network, long long keyGen, const String &recipients,
const String &plainMsg );
void repubRemoteBroadcastPublisher( User &user, Identity &peer,
FriendClaim &friendClaim, const String &messageId,
const String &network, long long generation, const String &recipients );
void repubRemoteBroadcastAuthor( User &user,
Identity &peer, FriendClaim &friendClaim,
const String &publisherIduri, const String &messageId,
const String &network, long long generation, const String &recipients );
void repubRemoteBroadcastSubject( User &user,
Identity &peer, FriendClaim &friendClaim,
const String &publisheriduri, const String &messageId,
const String &network, long long generation, const String &recipients );
void returnRemoteBroadcastAuthor( User &user, Identity &identity,
const String &reqid, const String &msg );
void returnRemoteBroadcastSubject( User &user, Identity &identity,
const String &reqid, const String &msg );
void notifyAccept( User &user, Identity &identity, const String &peerNotifyReqid );
void registered( User &user, Identity &identity,
const String &peerNotifyReqid, const String &friendClaimSigKey );
void storeBroadcastKey( User &user, Identity &identity, FriendClaim &friendClaim,
const String &distName, long long generation, const String &bkKeys );
void receiveBroadcast( const String &relid, const String &network,
long long keyGen, const String &msg );
void userMessage( MYSQL *mysql, const String &user,
const String &friendId, const String &body );
void queueBroadcast( User &user, String &msg );
void queueMessage( User &user, const String &iduri, const String &putRelid, const String &msg );
Allocated sendMessageNow( User &user,
const char *toIdentity, const char *putRelid, const String &msg );
void queueFofMessage( String &relid, Identity &recipient, const String &msg );
void sendBroadcastKey( User &user, Identity &identity,
FriendClaim &friendClaim, long long networkId );
void addToPrimaryNetwork( User &user, Identity &identity );
void parseBroadcast( Broadcast &b, const String &msg );
void broadcastContent( Broadcast &broadcast, const String &msg );
void remoteBroadcastPublisher( Broadcast &b, const String &publisher, const String &msg );
void remoteBroadcastAuthor( Broadcast &b, const String &author, const String &msg );
void remoteBroadcastSubject( Broadcast &b, const String &subject, const String &msg );
Allocated fetchPublicKeyNet( const String &host, const String &user );
Allocated fetchRequestedRelidNet( const String &host, const String &reqid );
Allocated fetchResponseRelidNet( const String &host, const String &reqid );
Allocated fetchFtokenNet( const String &host, const String &reqid );
void fetchPublicKey( Identity &identity );
void newBroadcastKey( long long friendGroupId, long long generation );
long long addNetwork( long long userId, const String &privateName );
void broadcastSuccessAuthor( User &user, Identity &identity, const String &messageId );
void broadcastSuccessSubject( User &user, Identity &identity, const String &messageId );
void rbBroadcastKey( User &user, Identity &friendId, Identity &senderId, const String &hash );
MYSQL *mysql;
};
struct TokenFlusher
:
public ConfigCtx
{
TokenFlusher( Config *c, NotifAgent ¬ifAgent )
:
ConfigCtx(c),
mysql(0),
notifAgent(notifAgent)
{}
MYSQL *mysql;
NotifAgent ¬ifAgent;
void flush();
void flushLoginTokens();
void flushFloginTokens();
};
struct QueueRunner
:
public ConfigCtx
{
QueueRunner( Config *c, TlsContext &tlsContext )
:
ConfigCtx(c),
tlsContext(tlsContext)
{}
bool sendBroadcastMessage();
bool sendMessage();
bool sendFofMessage();
long runBroadcastQueue();
long runMessageQueue();
long runFofMessageQueue();
void runQueue( const char *siteName );
void runQueue();
void runQueues( ConfigList &configList, int listenFd );
Allocated sendMessageNet( const String &host,
const String &relid, const String &msg );
Allocated sendFofMessageNet( const String &host,
const String &relid, const String &msg );
void sendBroadcastNet( const String &host, RecipientList &recipientList,
const String &network, long long keyGen, const String &msg );
TlsContext &tlsContext;
};
Allocated sha1( const String &src );
Allocated makeIduriHash( const char *identity );
long long findPrimaryNetworkId( MYSQL *mysql, User &user );
Allocated findPrimaryNetworkName( MYSQL *mysql, User &user );
#define LOGIN_TOKEN_LASTS 86400
struct Global
{
Global()
:
pid(0),