summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2018-12-06 12:47:58 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2018-12-06 12:47:58 -0800
commite6f9ab929df19ba667441b005ae2b9771922a92c (patch)
tree802a618a96d18b30ac22c13e00000e6aeafe7f73 /node
parent18d1772bb472770517dd5f863849d0d08defd71c (diff)
downloadinfinitytier-e6f9ab929df19ba667441b005ae2b9771922a92c.tar.gz
infinitytier-e6f9ab929df19ba667441b005ae2b9771922a92c.zip
More speed stuff.
Diffstat (limited to 'node')
-rw-r--r--node/C25519.cpp15
-rw-r--r--node/Multicaster.cpp8
-rw-r--r--node/Multicaster.hpp4
3 files changed, 17 insertions, 10 deletions
diff --git a/node/C25519.cpp b/node/C25519.cpp
index e3d23dee..209ac445 100644
--- a/node/C25519.cpp
+++ b/node/C25519.cpp
@@ -2003,6 +2003,7 @@ extern "C" void ed25519_amd64_asm_sign(const unsigned char *sk,const unsigned ch
namespace ZeroTier {
+#ifdef ZT_CONTROLLER
struct C25519CacheKey
{
uint64_t messageDigest[4];
@@ -2019,6 +2020,7 @@ struct C25519CacheValue
static uint64_t _ed25519TimestampCounter = 0;
static Hashtable<C25519CacheKey,C25519CacheValue> _ed25519Cache;
static Mutex _ed25519CacheLock;
+#endif
void C25519::agree(const C25519::Private &mine,const C25519::Public &their,void *keybuf,unsigned int keylen)
{
@@ -2041,6 +2043,7 @@ void C25519::sign(const C25519::Private &myPrivate,const C25519::Public &myPubli
unsigned char digest[64]; // we sign the first 32 bytes of SHA-512(msg)
SHA512::hash(digest,msg,len);
+#ifdef ZT_CONTROLLER
C25519CacheKey ck;
ZT_FAST_MEMCPY(ck.messageDigest,digest,32);
ZT_FAST_MEMCPY(ck.publicKey,myPublic.data + 32,32);
@@ -2053,6 +2056,7 @@ void C25519::sign(const C25519::Private &myPrivate,const C25519::Public &myPubli
ZT_FAST_MEMCPY(signature,cv->signature,ZT_C25519_SIGNATURE_LEN);
return;
}
+#endif
#ifdef ZT_USE_FAST_X64_ED25519
ed25519_amd64_asm_sign(myPrivate.data + 32,myPublic.data + 32,digest,(unsigned char *)signature);
@@ -2100,13 +2104,7 @@ void C25519::sign(const C25519::Private &myPrivate,const C25519::Public &myPubli
sig[32 + i] = s[i];
#endif
-/*
- Hashtable< Address,SharedPtr<Peer> >::Iterator i(_peers);
- Address *a = (Address *)0;
- SharedPtr<Peer> *p = (SharedPtr<Peer> *)0;
- while (i.next(a,p))
- _savePeer((void *)0,*p);
-*/
+#ifdef ZT_CONTROLLER
C25519CacheValue cvn;
memcpy(cvn.signature,signature,ZT_C25519_SIGNATURE_LEN);
{
@@ -2126,6 +2124,7 @@ void C25519::sign(const C25519::Private &myPrivate,const C25519::Public &myPubli
cvn.timestamp = ++_ed25519TimestampCounter;
_ed25519Cache.set(ck,cvn);
}
+#endif
}
bool C25519::verify(const C25519::Public &their,const void *msg,unsigned int len,const void *signature)
@@ -2136,6 +2135,7 @@ bool C25519::verify(const C25519::Public &their,const void *msg,unsigned int len
if (!Utils::secureEq(sig + 64,digest,32))
return false;
+#ifdef ZT_CONTROLLER
C25519CacheKey ck;
ZT_FAST_MEMCPY(ck.messageDigest,digest,32);
ZT_FAST_MEMCPY(ck.publicKey,their.data + 32,32);
@@ -2147,6 +2147,7 @@ bool C25519::verify(const C25519::Public &their,const void *msg,unsigned int len
if (cv) {
return Utils::secureEq(cv->signature,signature,ZT_C25519_SIGNATURE_LEN);
}
+#endif
unsigned char t2[32];
ge25519 get1, get2;
diff --git a/node/Multicaster.cpp b/node/Multicaster.cpp
index b2a5a205..2b5fb041 100644
--- a/node/Multicaster.cpp
+++ b/node/Multicaster.cpp
@@ -444,15 +444,17 @@ void Multicaster::_add(void *tPtr,int64_t now,uint64_t nwid,const MulticastGroup
if (member == RR->identity.address())
return;
- for(std::vector<MulticastGroupMember>::iterator m(gs.members.begin());m!=gs.members.end();++m) {
+ std::vector<MulticastGroupMember>::iterator m(std::lower_bound(gs.members.begin(),gs.members.end(),member));
+ if (m != gs.members.end()) {
if (m->address == member) {
m->timestamp = now;
return;
}
+ gs.members.insert(m,MulticastGroupMember(member,now));
+ } else {
+ gs.members.push_back(MulticastGroupMember(member,now));
}
- gs.members.push_back(MulticastGroupMember(member,now));
-
for(std::list<OutboundMulticast>::iterator tx(gs.txQueue.begin());tx!=gs.txQueue.end();) {
if (tx->atLimit())
gs.txQueue.erase(tx++);
diff --git a/node/Multicaster.hpp b/node/Multicaster.hpp
index e57f81fe..c6c2a209 100644
--- a/node/Multicaster.hpp
+++ b/node/Multicaster.hpp
@@ -203,6 +203,10 @@ private:
MulticastGroupMember() {}
MulticastGroupMember(const Address &a,uint64_t ts) : address(a),timestamp(ts) {}
+ inline bool operator<(const Address &a) const { return (address < a); }
+ inline bool operator==(const Address &a) const { return (address == a); }
+ inline bool operator!=(const Address &a) const { return (address != a); }
+
Address address;
uint64_t timestamp; // time of last notification
};