Classified ads
protocol.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Järvinen 2013.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Classified Ads. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef CA_PROTOCOL_H
21 #define CA_PROTOCOL_H
22 #include "../util/hash.h" // for Hash
23 
40 // node greeting has following fields, each is unsigned
41 // 8-bit if not otherwise stated, 32-bit integers are
42 // in network byte order:
43 // 1. protocol version for this node. Note that identifies
44 // both this message and the protocol version. Later we
45 // may invent protocol version xyz that will then
46 // identify node and its protocol with some other
47 // number.
48 static const unsigned char KProtocolVersion (1) ;
49 // 2. number of bytes that follows for the whole message
50 // 3. node greeting as qCompress()ed JSon
51 //
52 // ok, next thing to define is our easiest message type, random numbers.
53 // idea for this is this: upon connect node sends node greeting.
54 // node greeting contains hash and outside ip addr. suppose someone
55 // is eavesdropping the tsl tcp connection she already has some known
56 // plaintext in there, in the very first real datapacket transmitted,
57 // in known offset so .. say, the original tsl key was done using bad
58 // random number and in addition the listener knows some plaintext
59 // inside it might be possible to brute-force the key.
60 //
61 // lets make her job a bit more interesting by first transmitting
62 // short random sequence of random length in the beginning.
63 static const unsigned char KRandomNumbersPacket (100) ;
64 // rest of the packet is msg len and then the bytes that are supposed
65 // to be discarded (or written into your weekly lottery ticket
66 // if you consider yourself a lucky jerk :)
67 
68 // then have packet for requesting nodes that might be held liable
69 // for keeping alive content with given hash
70 // the packet consists of the identifier and a 160 bit hash. nothing else.
71 
72 // following items are for requesting various things from peer:
73 static const unsigned char KNodesAroundHash (101) ;
74 static const unsigned char KProfileAtHash (103) ;
75 static const unsigned char KBinaryFileAtHash (104) ;
76 static const unsigned char KClassifiedAdAtHash (109) ;
78 static const unsigned char KProfilePublish (102) ;
79 static const unsigned char KBinaryFilePublish (105) ;
80 static const unsigned char KBinaryFileSend (106) ;
81 static const unsigned char KClassifiedAdPublish (107) ;
82 static const unsigned char KProfileSend (108) ;
83 static const unsigned char KClassifiedAdSend (110) ;
84 static const unsigned char KAdsClassifiedAtHash (111) ;
85 static const unsigned char KListOfAdsClassifiedAtHash (112) ;
86 static const unsigned char KPrivMessagePublish (113) ;
87 static const unsigned char KPrivMessageSend (114) ;
88 static const unsigned char KPrivMessagesAtHash (115) ;
89 static const unsigned char KPrivMessagesForProfile (116) ;
90 static const unsigned char KProfileCommentPublish (117) ;
91 static const unsigned char KProfileCommentSend (118) ;
97 static const unsigned char KProfileCommentAtHash (119) ;
101 static const unsigned char KSingleProfileCommentAtHash (120) ;
105 static const unsigned char KSearchRequest (121) ;
109 static const unsigned char KSearchResults (122) ;
113 static const unsigned char KFutureUse1 (123) ;
114 static const unsigned char KFutureUse2 (124) ;
115 static const unsigned char KFutureUse3 (125) ;
116 static const unsigned char KFutureUse4 (126) ;
117 static const unsigned char KFutureUse5 (127) ;
118 static const unsigned char KFutureUse6 (128) ;
150 };
160 } ;
168 struct PublishItem {
172  QList<quint32> iAlreadyPushedHosts ;
174 } ;
175 
179 static const int KMaxOpenConnections( 100 );
185 static const int KNumberOfNodesToSendToEachPeer ( 300 ) ;
190 static const int KNumberOfClassifiedAdsToSendToEachPeer ( 300 ) ;
194 static const quint32 KMaxProtocolItemSize ( 1024*1024*2 ) ;
195 
200 static const quint16 KBroadCastAdvertismentPort ( 23432 ) ;
201 #endif /* CA_PROTOCOL_H */
static const unsigned char KClassifiedAdAtHash(109)
Definition: protocol.h:136
Definition: protocol.h:141
static const unsigned char KBinaryFilePublish(105)
static const unsigned char KSearchResults(122)
Definition: protocol.h:131
static const unsigned char KProfilePublish(102)
Definition: protocol.h:147
static const unsigned char KBinaryFileSend(106)
static const unsigned char KProtocolVersion(1)
Hash i2NdAddr
Definition: protocol.h:173
Definition: protocol.h:137
static const unsigned char KNodesAroundHash(101)
static const unsigned char KAdsClassifiedAtHash(111)
static const unsigned char KFutureUse3(125)
static const unsigned char KListOfAdsClassifiedAtHash(112)
Definition: protocol.h:144
Definition: protocol.h:140
Definition: protocol.h:139
Definition: protocol.h:134
static const quint32 KMaxProtocolItemSize(1024 *1024 *2)
Definition: protocol.h:143
Hash is class that carries 160-bit digest.
Definition: hash.h:37
Definition: protocol.h:128
static const unsigned char KFutureUse4(126)
static const unsigned char KFutureUse2(124)
static const unsigned char KSearchRequest(121)
ProtocolItemType
Definition: protocol.h:124
Definition: protocol.h:127
Definition: protocol.h:148
static const unsigned char KPrivMessagePublish(113)
ProtocolItemType iItemType
Definition: protocol.h:158
Definition: protocol.h:145
static const int KNumberOfNodesToSendToEachPeer(300)
Definition: protocol.h:133
static const unsigned char KPrivMessagesAtHash(115)
static const unsigned char KFutureUse6(128)
static const quint16 KBroadCastAdvertismentPort(23432)
Definition: protocol.h:129
static const unsigned char KClassifiedAdPublish(107)
static const unsigned char KProfileCommentAtHash(119)
static const unsigned char KSingleProfileCommentAtHash(120)
Hash iObjectHash
Definition: protocol.h:170
Definition: protocol.h:142
static const unsigned char KProfileCommentSend(118)
static const unsigned char KPrivMessagesForProfile(116)
Definition: protocol.h:130
Definition: protocol.h:146
send-queue item.
Definition: protocol.h:157
static const unsigned char KFutureUse1(123)
static const unsigned char KPrivMessageSend(114)
static const unsigned char KClassifiedAdSend(110)
static const unsigned char KProfileSend(108)
Definition: protocol.h:149
static const unsigned char KFutureUse5(127)
static const int KNumberOfClassifiedAdsToSendToEachPeer(300)
Carrier for keeping state of item about to be published.
Definition: protocol.h:168
Definition: protocol.h:126
static const unsigned char KProfileAtHash(103)
static const int KMaxOpenConnections(100)
static const unsigned char KProfileCommentPublish(117)
static const unsigned char KBinaryFileAtHash(104)
Definition: protocol.h:132
ProtocolItemType iObjectType
Definition: protocol.h:169
Hash iHash
Definition: protocol.h:159
Definition: protocol.h:135
Definition: protocol.h:125
static const unsigned char KRandomNumbersPacket(100)
Definition: protocol.h:138
QList< quint32 > iAlreadyPushedHosts
Definition: protocol.h:172