Tons more refactoring: simplify Network, move explicit management of Tap out, redo COM serialization, etc.
This commit is contained in:
parent
49349470a0
commit
1f28ce3980
11 changed files with 240 additions and 487 deletions
|
@ -40,6 +40,7 @@
|
|||
#include "Address.hpp"
|
||||
#include "C25519.hpp"
|
||||
#include "Identity.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
|
@ -314,9 +315,80 @@ public:
|
|||
*/
|
||||
inline const Address &signedBy() const throw() { return _signedBy; }
|
||||
|
||||
/**
|
||||
* Serialize to std::string or compatible class
|
||||
*
|
||||
* @param b String or other class supporting push_back() and append() like std::string
|
||||
*/
|
||||
template<typename T>
|
||||
inline void serialize2(T &b) const
|
||||
{
|
||||
uint64_t tmp[3];
|
||||
char tmp2[ZT_ADDRESS_LENGTH];
|
||||
b.push_back((char)COM_UINT64_ED25519);
|
||||
b.push_back((char)((_qualifiers.size() >> 8) & 0xff));
|
||||
b.push_back((char)(_qualifiers.size() & 0xff));
|
||||
for(std::vector<_Qualifier>::const_iterator q(_qualifiers.begin());q!=_qualifiers.end();++q) {
|
||||
tmp[0] = Utils::hton(q->id);
|
||||
tmp[1] = Utils::hton(q->value);
|
||||
tmp[2] = Utils::hton(q->maxDelta);
|
||||
b.append(reinterpret_cast<const char *>(reinterpret_cast<void *>(tmp)),sizeof(tmp));
|
||||
}
|
||||
_signedBy.copyTo(tmp2,ZT_ADDRESS_LENGTH);
|
||||
b.append(tmp2,ZT_ADDRESS_LENGTH);
|
||||
if (_signedBy)
|
||||
b.append((const char *)_signature.data,_signature.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize from std::string::iterator or compatible iterator or char* pointer
|
||||
*
|
||||
* @param p Iterator
|
||||
* @param end End of buffer
|
||||
*/
|
||||
template<typename T>
|
||||
inline void deserialize2(T &p,const T &end)
|
||||
{
|
||||
uint64_t tmp[3];
|
||||
char tmp2[ZT_ADDRESS_LENGTH];
|
||||
unsigned int qcount;
|
||||
|
||||
_qualifiers.clear();
|
||||
_signedBy.zero();
|
||||
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
if (*(p++) != (char)COM_UINT64_ED25519) throw std::invalid_argument("unknown certificate of membership type");
|
||||
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
qcount = (unsigned int)*(p++) << 8;
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
qcount |= (unsigned int)*(p++);
|
||||
|
||||
for(unsigned int i=0;i<qcount;++i) {
|
||||
char *p2 = reinterpret_cast<char *>(reinterpret_cast<void *>(tmp));
|
||||
for(unsigned int j=0;j<sizeof(tmp);++j) {
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
*(p2++) = *(p++);
|
||||
}
|
||||
_qualifiers.push_back(_Qualifier(Utils::ntoh(tmp[0]),Utils::ntoh(tmp[1]),Utils::ntoh(tmp[2])));
|
||||
}
|
||||
|
||||
for(unsigned int j=0;j<ZT_ADDRESS_LENGTH;++j) {
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
tmp2[j] = *(p++);
|
||||
}
|
||||
_signedBy.setTo(tmp2,ZT_ADDRESS_LENGTH);
|
||||
|
||||
if (_signedBy) {
|
||||
for(unsigned int j=0;j<_signature.size();++j) {
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
_signature.data[j] = (unsigned char)*(p++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<unsigned int C>
|
||||
inline void serialize(Buffer<C> &b) const
|
||||
throw(std::out_of_range)
|
||||
{
|
||||
b.append((unsigned char)COM_UINT64_ED25519);
|
||||
b.append((uint16_t)_qualifiers.size());
|
||||
|
@ -332,7 +404,6 @@ public:
|
|||
|
||||
template<unsigned int C>
|
||||
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
|
||||
throw(std::out_of_range,std::invalid_argument)
|
||||
{
|
||||
unsigned int p = startAt;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue