-
Notifications
You must be signed in to change notification settings - Fork 1
/
GlobalGrid.h
92 lines (73 loc) · 2.7 KB
/
GlobalGrid.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
/*
This file is part of the GlobalGrid Protocol Suite.
GlobalGrid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GlobalGrid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GlobalGrid. If not, see <http://www.gnu.org/licenses/>.
* */
#ifndef GG_VS
#define GG_VS
#include <stddef.h>
#include <memory>
#include <string.h>
namespace GlobalGrid {
class VSocket {
public:
virtual void Send(const void* data, size_t sz) = 0;
/**
* @summary Serializes this VSocket to a Buffer, which must be freed by calling GGObject_Free
* */
virtual void* Serialize() = 0;
virtual void GetProtocolID(void* outbuff) = 0;
virtual ~VSocket(){};
};
class Guid {
public:
uint64_t value[2];
Guid() {
}
Guid(const uint64_t* val) {
value[0] = val[0];
value[1] = val[1];
}
Guid(const unsigned char* val) {
memcpy(value,val,16);
}
bool operator==(const Guid& other) const {
return (value[0] == other.value[0]) && (value[1] == other.value[1]);
}
bool operator!=(const Guid& other) const {
return !((value[0] == other.value[0]) && (value[1] == other.value[1]));
}
bool operator<(const Guid& other) const {
return memcmp(value,other.value,16) < 0;
}
};
class ProtocolDriver {
public:
//Protocol driver ID
Guid id;
virtual std::shared_ptr<VSocket> Deserialize(unsigned char* buffer, size_t bufflen) = 0;
virtual void* SerializeLocalSocket() = 0; //Serializes a socket containing localized connection information. Can be used for diagnostics purposes.
virtual ~ProtocolDriver(){};
};
void* Buffer_Create(size_t sz);
void Buffer_Get(void* buffer,void** out, size_t* sz);
template<typename T>
static inline void Buffer_Get(void* buffer, T** out, size_t* sz) {
Buffer_Get(buffer,(void**)out,sz);
}
void GGObject_Free(void* obj);
void GlobalGrid_NtfyPacket(void* connectionManager, std::shared_ptr<VSocket>, unsigned char* packet, size_t packetlength);
void* GlobalGrid_InitRouter(void* encryptionKey);
void GlobalGrid_RegisterProtocolDriver(void* connectionManager,std::shared_ptr<ProtocolDriver> driver);
void GlobalGrid_InitiateHandshake(void* connectionManager, std::shared_ptr<VSocket> socket, void* remoteKey);
void GlobalGrid_SendPacket(void* connectionManager, const Guid& dest, unsigned char* data, size_t sz);
}
#endif