From 2da096944d203320c44ee523fbc9a295d4f020b1 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 18 Mar 2020 07:20:04 -0700 Subject: [PATCH] Everything but root builds now. Back to testing. --- CMakeLists.txt | 2 +- controller/LFDB.cpp | 2 +- go/pkg/zerotier/node.go | 33 ++++++++++++++++----------------- go/pkg/zerotier/peer.go | 2 +- include/ZeroTierCore.h | 5 +++++ node/Node.cpp | 2 ++ osdep/MacEthernetTapAgent.c | 2 +- root/root.cpp | 12 ++++++------ 8 files changed, 33 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fbb5e6ff..e5d1fd672 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,7 +105,7 @@ endif() add_subdirectory(node) add_subdirectory(controller) add_subdirectory(osdep) -add_subdirectory(root) +#add_subdirectory(root) add_subdirectory(go/native) #if(BUILD_CENTRAL_CONTROLLER) diff --git a/controller/LFDB.cpp b/controller/LFDB.cpp index caf71f55e..a4fca6135 100644 --- a/controller/LFDB.cpp +++ b/controller/LFDB.cpp @@ -99,7 +99,7 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons selectors.push_back(selector1); newrec["Selectors"] = selectors; const uint8_t *const rawip = (const uint8_t *)ms->second.lastOnlineAddress.rawIpData(); - switch(ms->second.lastOnlineAddress.ss_family) { + switch(ms->second.lastOnlineAddress.family()) { case AF_INET: for(int j=0;j<4;++j) ip.push_back((unsigned int)rawip[j]); diff --git a/go/pkg/zerotier/node.go b/go/pkg/zerotier/node.go index 7fe87ca71..d6125cd02 100644 --- a/go/pkg/zerotier/node.go +++ b/go/pkg/zerotier/node.go @@ -21,7 +21,6 @@ import "C" import ( "bytes" - "encoding/hex" "errors" "fmt" "io" @@ -71,15 +70,15 @@ var ( nodesByUserPtrCtr = uintptr(0) nodesByUserPtrLock sync.RWMutex - CoreVersionMajor int - CoreVersionMinor int + CoreVersionMajor int + CoreVersionMinor int CoreVersionRevision int - CoreVersionBuild int + CoreVersionBuild int ) func init() { - var vMaj,vMin,vRev,vBuild C.int - C.ZT_version(&vMaj,&vMin,&vRev,&vBuild) + var vMaj, vMin, vRev, vBuild C.int + C.ZT_version(&vMaj, &vMin, &vRev, &vBuild) CoreVersionMajor = int(vMaj) CoreVersionMinor = int(vMin) CoreVersionRevision = int(vRev) @@ -122,7 +121,7 @@ type Node struct { gn *C.ZT_GoNode // zn is the underlying instance of the ZeroTier core - zn *C.ZT_Node + zn unsafe.Pointer // id is the identity of this node id *Identity @@ -263,8 +262,8 @@ func NewNode(basePath string) (n *Node, err error) { nodesByUserPtrLock.Unlock() return nil, ErrNodeInitFailed } - n.zn = (*C.ZT_Node)(C.ZT_GoNode_getNode(n.gn)) - n.id, err = newIdentityFromCIdentity(C.ZT_Node_identity(unsafe.Pointer(n.zn))) + n.zn = unsafe.Pointer(C.ZT_GoNode_getNode(n.gn)) + n.id, err = newIdentityFromCIdentity(C.ZT_Node_identity(n.zn)) if err != nil { n.infoLog.Printf("FATAL: error obtaining node's identity") nodesByUserPtrLock.Lock() @@ -393,9 +392,9 @@ func NewNode(basePath string) (n *Node, err error) { } cAddrCount++ } - C.ZT_Node_setInterfaceAddresses(unsafe.Pointer(n.zn), &cAddrs[0], C.uint(cAddrCount)) + C.ZT_Node_setInterfaceAddresses(n.zn, &cAddrs[0], C.uint(cAddrCount)) } else { - C.ZT_Node_setInterfaceAddresses(unsafe.Pointer(n.zn), nil, 0) + C.ZT_Node_setInterfaceAddresses(n.zn, nil, 0) } } @@ -597,14 +596,14 @@ func (n *Node) Networks() []*Network { // Peers retrieves a list of current peers func (n *Node) Peers() []*Peer { var peers []*Peer - pl := C.ZT_Node_peers(unsafe.Pointer(n.zn)) + pl := C.ZT_Node_peers(n.zn) if pl != nil { for i := uintptr(0); i < uintptr(pl.peerCount); i++ { p := (*C.ZT_Peer)(unsafe.Pointer(uintptr(unsafe.Pointer(pl.peers)) + (i * C.sizeof_ZT_Peer))) p2 := new(Peer) p2.Address = Address(p.address) p2.Identity, _ = newIdentityFromCIdentity(unsafe.Pointer(p.identity)) - p2.IdentityHash = hex.EncodeToString((*[48]byte)(unsafe.Pointer(&p.identityHash[0]))[:]) + p2.Fingerprint = C.GoBytes(unsafe.Pointer(&p.fingerprint.hash[0]), 48) p2.Version = [3]int{int(p.versionMajor), int(p.versionMinor), int(p.versionRev)} p2.Latency = int(p.latency) p2.Root = p.root != 0 @@ -612,7 +611,7 @@ func (n *Node) Peers() []*Peer { p2.Paths = make([]Path, 0, int(p.pathCount)) for j := 0; j < len(p2.Paths); j++ { - pt := &p.paths[j] + pt := (*C.ZT_PeerPhysicalPath)(unsafe.Pointer(uintptr(unsafe.Pointer(p.paths)) + uintptr(j * C.sizeof_ZT_PeerPhysicalPath))) if pt.alive != 0 { a := sockaddrStorageToUDPAddr(&pt.address) if a != nil { @@ -629,7 +628,7 @@ func (n *Node) Peers() []*Peer { peers = append(peers, p2) } - C.ZT_Node_freeQueryResult(unsafe.Pointer(n.zn), unsafe.Pointer(pl)) + C.ZT_Node_freeQueryResult(n.zn, unsafe.Pointer(pl)) } sort.Slice(peers, func(a, b int) bool { return peers[a].Address < peers[b].Address @@ -640,11 +639,11 @@ func (n *Node) Peers() []*Peer { // -------------------------------------------------------------------------------------------------------------------- func (n *Node) multicastSubscribe(nwid uint64, mg *MulticastGroup) { - C.ZT_Node_multicastSubscribe(unsafe.Pointer(n.zn), nil, C.uint64_t(nwid), C.uint64_t(mg.MAC), C.ulong(mg.ADI)) + C.ZT_Node_multicastSubscribe(n.zn, nil, C.uint64_t(nwid), C.uint64_t(mg.MAC), C.ulong(mg.ADI)) } func (n *Node) multicastUnsubscribe(nwid uint64, mg *MulticastGroup) { - C.ZT_Node_multicastUnsubscribe(unsafe.Pointer(n.zn), C.uint64_t(nwid), C.uint64_t(mg.MAC), C.ulong(mg.ADI)) + C.ZT_Node_multicastUnsubscribe(n.zn, C.uint64_t(nwid), C.uint64_t(mg.MAC), C.ulong(mg.ADI)) } func (n *Node) pathCheck(ip net.IP) bool { diff --git a/go/pkg/zerotier/peer.go b/go/pkg/zerotier/peer.go index c2a18a805..cb49308bf 100644 --- a/go/pkg/zerotier/peer.go +++ b/go/pkg/zerotier/peer.go @@ -17,7 +17,7 @@ package zerotier type Peer struct { Address Address `json:"address"` Identity *Identity `json:"identity"` - IdentityHash string `json:"identityHash"` + Fingerprint []byte `json:"fingerprint"` Version [3]int `json:"version"` Latency int `json:"latency"` Root bool `json:"root"` diff --git a/include/ZeroTierCore.h b/include/ZeroTierCore.h index 70942a0fe..b3921d3b1 100644 --- a/include/ZeroTierCore.h +++ b/include/ZeroTierCore.h @@ -1361,6 +1361,11 @@ typedef struct */ const ZT_Identity *identity; + /** + * SHA-384 of identity public key(s) + */ + ZT_Fingerprint fingerprint; + /** * Remote major version or -1 if not known */ diff --git a/node/Node.cpp b/node/Node.cpp index f11869496..6e3544319 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -483,6 +483,8 @@ ZT_PeerList *Node::peers() const p->address = (*pi)->address().toInt(); identities[pl->peerCount] = (*pi)->identity(); // need to make a copy in case peer gets deleted p->identity = &identities[pl->peerCount]; + p->fingerprint.address = p->address; + memcpy(p->fingerprint.hash,(*pi)->identity().fingerprint().hash(),ZT_IDENTITY_HASH_SIZE); if ((*pi)->remoteVersionKnown()) { p->versionMajor = (int)(*pi)->remoteVersionMajor(); p->versionMinor = (int)(*pi)->remoteVersionMinor(); diff --git a/osdep/MacEthernetTapAgent.c b/osdep/MacEthernetTapAgent.c index 4c563f231..1e7d69e38 100644 --- a/osdep/MacEthernetTapAgent.c +++ b/osdep/MacEthernetTapAgent.c @@ -308,7 +308,7 @@ int main(int argc,char **argv) return ZT_MACETHERNETTAPAGENT_EXIT_CODE_UNABLE_TO_CREATE; } - fprintf(stderr,"I %s %s %d.%d.%d.%d\n",s_deviceName,s_peerDeviceName,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION,ZEROTIER_ONE_VERSION_BUILD); + fprintf(stderr,"I %s %s %d.%d.%d.%d\n",s_deviceName,s_peerDeviceName,ZEROTIER_VERSION_MAJOR,ZEROTIER_VERSION_MINOR,ZEROTIER_VERSION_REVISION,ZEROTIER_VERSION_BUILD); FD_ZERO(&rfds); FD_ZERO(&wfds); diff --git a/root/root.cpp b/root/root.cpp index c9a94297d..8e41431d8 100644 --- a/root/root.cpp +++ b/root/root.cpp @@ -74,7 +74,7 @@ #include #include -#include +#include #include #include #include @@ -140,7 +140,7 @@ struct RootPeer int vProto; // Protocol version or -1 if unknown int vMajor,vMinor,vRev; // Peer version or -1,-1,-1 if unknown - Atomic __refCount; + std::atomic __refCount; }; // Hashers for std::unordered_map @@ -191,10 +191,10 @@ static std::map< std::pair< uint32_t,uint32_t >,std::pair< float,float > > s_geo static std::map< std::pair< std::array< uint64_t,2 >,std::array< uint64_t,2 > >,std::pair< float,float > > s_geoIp6; // Rate meters for statistical purposes (locks are internal to Meter) -static Meter s_inputRate; -static Meter s_outputRate; -static Meter s_forwardRate; -static Meter s_discardedForwardRate; +static Meter<> s_inputRate; +static Meter<> s_outputRate; +static Meter<> s_forwardRate; +static Meter<> s_discardedForwardRate; // These fields are locked using mutexes below as they're modified during runtime static std::string s_planet;