mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
Cleanup, revise join command
This commit is contained in:
parent
fe28501126
commit
e2ca065f28
10 changed files with 57 additions and 45 deletions
|
@ -34,11 +34,11 @@ Global Options:
|
||||||
Commands:
|
Commands:
|
||||||
help Show this help
|
help Show this help
|
||||||
version Print version
|
version Print version
|
||||||
service Start as service
|
service Start a node (see below)
|
||||||
status Show node status and configuration
|
status Show node status and configuration
|
||||||
join <network> [option] Join a virtual network
|
join [-options] <network> Join a virtual network
|
||||||
auth <token> Join authorization token
|
-a <token> Join authorization token
|
||||||
fingerprint <fingerprint> Full controller identity fingerprint
|
-c <identity|fingerprint> Controller identity or fingerprint
|
||||||
leave <network> Leave a virtual network
|
leave <network> Leave a virtual network
|
||||||
networks List VL2 virtual networks
|
networks List VL2 virtual networks
|
||||||
network <network> [command] [option] - Network management commands
|
network <network> [command] [option] - Network management commands
|
||||||
|
@ -82,8 +82,6 @@ Commands:
|
||||||
sign <identity> <file> Sign a file with an identity's key
|
sign <identity> <file> Sign a file with an identity's key
|
||||||
verify <identity> <file> <sig> Verify a signature
|
verify <identity> <file> <sig> Verify a signature
|
||||||
|
|
||||||
The 'service' command does not exit until the service receives a signal.
|
|
||||||
|
|
||||||
An <address> may be specified as a 10-digit short ZeroTier address, a
|
An <address> may be specified as a 10-digit short ZeroTier address, a
|
||||||
fingerprint containing both an address and a SHA384 hash, or an identity.
|
fingerprint containing both an address and a SHA384 hash, or an identity.
|
||||||
The latter two options are equivalent in terms of specificity and may be
|
The latter two options are equivalent in terms of specificity and may be
|
||||||
|
@ -93,5 +91,8 @@ full identities and may be specified either verbatim or as a path to a file.
|
||||||
|
|
||||||
An <endpoint> is a place where a peer may be reached. Currently these are
|
An <endpoint> is a place where a peer may be reached. Currently these are
|
||||||
just 'IP/port' format addresses but other types may be added in the future.
|
just 'IP/port' format addresses but other types may be added in the future.
|
||||||
|
|
||||||
|
The 'service' command starts a node. It will run until the node receives
|
||||||
|
an exit signal and is normally not used directly.
|
||||||
`,zerotier.CoreVersionMajor, zerotier.CoreVersionMinor, zerotier.CoreVersionRevision)
|
`,zerotier.CoreVersionMajor, zerotier.CoreVersionMinor, zerotier.CoreVersionRevision)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -22,17 +23,47 @@ import (
|
||||||
"zerotier/pkg/zerotier"
|
"zerotier/pkg/zerotier"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Join CLI command
|
|
||||||
func Join(basePath, authToken string, args []string) {
|
func Join(basePath, authToken string, args []string) {
|
||||||
if len(args) < 1 || len(args) > 2 {
|
joinOpts := flag.NewFlagSet("join", flag.ContinueOnError)
|
||||||
|
controllerAuthToken := joinOpts.String("a", "", "")
|
||||||
|
controllerFingerprint := joinOpts.String("c", "", "")
|
||||||
|
err := joinOpts.Parse(os.Args[1:])
|
||||||
|
if err != nil {
|
||||||
Help()
|
Help()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
args = joinOpts.Args()
|
||||||
|
if len(args) < 1 {
|
||||||
|
Help()
|
||||||
|
os.Exit(1)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args[0]) != zerotier.NetworkIDStringLength {
|
if len(args[0]) != zerotier.NetworkIDStringLength {
|
||||||
fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
|
fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = *controllerAuthToken // TODO: not implemented yet
|
||||||
|
|
||||||
|
var fp *zerotier.Fingerprint
|
||||||
|
if len(*controllerFingerprint) > 0 {
|
||||||
|
if strings.ContainsRune(*controllerFingerprint, '-') {
|
||||||
|
fp, err = zerotier.NewFingerprintFromString(*controllerFingerprint)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: invalid network controller fingerprint: %s\n", *controllerFingerprint)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
id, err := zerotier.NewIdentityFromString(*controllerFingerprint)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: invalid network controller identity: %s\n", *controllerFingerprint)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fp = id.Fingerprint()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nwid, err := strconv.ParseUint(args[0], 16, 64)
|
nwid, err := strconv.ParseUint(args[0], 16, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
|
fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
|
||||||
|
@ -40,24 +71,6 @@ func Join(basePath, authToken string, args []string) {
|
||||||
}
|
}
|
||||||
nwids := fmt.Sprintf("%.16x", nwid)
|
nwids := fmt.Sprintf("%.16x", nwid)
|
||||||
|
|
||||||
var fp *zerotier.Fingerprint
|
|
||||||
if len(args) == 2 {
|
|
||||||
if strings.ContainsRune(args[1], '-') {
|
|
||||||
fp, err = zerotier.NewFingerprintFromString(args[1])
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: invalid network controller fingerprint: %s\n", args[1])
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
id, err := zerotier.NewIdentityFromString(args[1])
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: invalid network controller identity: %s\n", args[1])
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
fp = id.Fingerprint()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var network zerotier.APINetwork
|
var network zerotier.APINetwork
|
||||||
network.ID = zerotier.NetworkID(nwid)
|
network.ID = zerotier.NetworkID(nwid)
|
||||||
network.ControllerFingerprint = fp
|
network.ControllerFingerprint = fp
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"zerotier/pkg/zerotier"
|
"zerotier/pkg/zerotier"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Leave CLI command
|
|
||||||
func Leave(basePath, authToken string, args []string) {
|
func Leave(basePath, authToken string, args []string) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
Help()
|
Help()
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"zerotier/pkg/zerotier"
|
"zerotier/pkg/zerotier"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Networks CLI command
|
|
||||||
func Networks(basePath, authToken string, args []string, jsonOutput bool) {
|
func Networks(basePath, authToken string, args []string, jsonOutput bool) {
|
||||||
var networks []zerotier.APINetwork
|
var networks []zerotier.APINetwork
|
||||||
apiGet(basePath, authToken, "/network", &networks)
|
apiGet(basePath, authToken, "/network", &networks)
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"zerotier/pkg/zerotier"
|
"zerotier/pkg/zerotier"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Peers CLI command (also used for 'roots' command with rootsOnly set to true)
|
|
||||||
func Peers(basePath, authToken string, args []string, jsonOutput bool, rootsOnly bool) {
|
func Peers(basePath, authToken string, args []string, jsonOutput bool, rootsOnly bool) {
|
||||||
var peers []zerotier.Peer
|
var peers []zerotier.Peer
|
||||||
apiGet(basePath, authToken, "/peer", &peers)
|
apiGet(basePath, authToken, "/peer", &peers)
|
||||||
|
|
|
@ -21,6 +21,10 @@ func Root(basePath, authToken string, args []string, jsonOutput bool) {
|
||||||
|
|
||||||
case "remove":
|
case "remove":
|
||||||
|
|
||||||
|
case "subscribe":
|
||||||
|
|
||||||
|
case "unsubscribe":
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"zerotier/pkg/zerotier"
|
"zerotier/pkg/zerotier"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Service is "zerotier service ..."
|
|
||||||
func Service(basePath, authToken string, args []string) {
|
func Service(basePath, authToken string, args []string) {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
Help()
|
Help()
|
||||||
|
|
|
@ -13,6 +13,5 @@
|
||||||
|
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
// Set CLI command
|
|
||||||
func Set(basePath, authToken string, args []string) {
|
func Set(basePath, authToken string, args []string) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"zerotier/pkg/zerotier"
|
"zerotier/pkg/zerotier"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Status shows service status info
|
|
||||||
func Status(basePath, authToken string, args []string, jsonOutput bool) {
|
func Status(basePath, authToken string, args []string, jsonOutput bool) {
|
||||||
var status zerotier.APIStatus
|
var status zerotier.APIStatus
|
||||||
apiGet(basePath, authToken, "/status", &status)
|
apiGet(basePath, authToken, "/status", &status)
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace ZeroTier {
|
||||||
class Mutex
|
class Mutex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ZT_INLINE Mutex() noexcept { pthread_mutex_init(&_mh,nullptr); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
ZT_INLINE Mutex() noexcept { pthread_mutex_init(&_mh,nullptr); }
|
||||||
ZT_INLINE ~Mutex() noexcept { pthread_mutex_destroy(&_mh); }
|
ZT_INLINE ~Mutex() noexcept { pthread_mutex_destroy(&_mh); }
|
||||||
|
|
||||||
ZT_INLINE void lock() const noexcept { pthread_mutex_lock(&((const_cast <Mutex *> (this))->_mh)); }
|
ZT_INLINE void lock() const noexcept { pthread_mutex_lock(&((const_cast <Mutex *> (this))->_mh)); }
|
||||||
|
@ -37,15 +37,15 @@ public:
|
||||||
class Lock
|
class Lock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ZT_INLINE Lock(Mutex &m) noexcept : _m(&m) { m.lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
explicit ZT_INLINE Lock(Mutex &m) noexcept : _m(&m) { m.lock(); }
|
||||||
explicit ZT_INLINE Lock(const Mutex &m) noexcept : _m(const_cast<Mutex *>(&m)) { _m->lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
explicit ZT_INLINE Lock(const Mutex &m) noexcept : _m(const_cast<Mutex *>(&m)) { _m->lock(); }
|
||||||
ZT_INLINE ~Lock() { _m->unlock(); }
|
ZT_INLINE ~Lock() { _m->unlock(); }
|
||||||
private:
|
private:
|
||||||
Mutex *const _m;
|
Mutex *const _m;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ZT_INLINE Mutex(const Mutex &) noexcept {} // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
ZT_INLINE Mutex(const Mutex &) noexcept {}
|
||||||
ZT_INLINE const Mutex &operator=(const Mutex &) noexcept { return *this; }
|
ZT_INLINE const Mutex &operator=(const Mutex &) noexcept { return *this; }
|
||||||
|
|
||||||
pthread_mutex_t _mh;
|
pthread_mutex_t _mh;
|
||||||
|
@ -54,7 +54,7 @@ private:
|
||||||
class RWMutex
|
class RWMutex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ZT_INLINE RWMutex() noexcept { pthread_rwlock_init(&_mh,nullptr); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
ZT_INLINE RWMutex() noexcept { pthread_rwlock_init(&_mh,nullptr); }
|
||||||
ZT_INLINE ~RWMutex() noexcept { pthread_rwlock_destroy(&_mh); }
|
ZT_INLINE ~RWMutex() noexcept { pthread_rwlock_destroy(&_mh); }
|
||||||
|
|
||||||
ZT_INLINE void lock() const noexcept { pthread_rwlock_wrlock(&((const_cast <RWMutex *> (this))->_mh)); }
|
ZT_INLINE void lock() const noexcept { pthread_rwlock_wrlock(&((const_cast <RWMutex *> (this))->_mh)); }
|
||||||
|
@ -68,8 +68,8 @@ public:
|
||||||
class RLock
|
class RLock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ZT_INLINE RLock(RWMutex &m) noexcept : _m(&m) { m.rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
explicit ZT_INLINE RLock(RWMutex &m) noexcept : _m(&m) { m.rlock(); }
|
||||||
explicit ZT_INLINE RLock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)) { _m->rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
explicit ZT_INLINE RLock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)) { _m->rlock(); }
|
||||||
ZT_INLINE ~RLock() { _m->runlock(); }
|
ZT_INLINE ~RLock() { _m->runlock(); }
|
||||||
private:
|
private:
|
||||||
RWMutex *const _m;
|
RWMutex *const _m;
|
||||||
|
@ -81,8 +81,8 @@ public:
|
||||||
class Lock
|
class Lock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ZT_INLINE Lock(RWMutex &m) noexcept : _m(&m) { m.lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
explicit ZT_INLINE Lock(RWMutex &m) noexcept : _m(&m) { m.lock(); }
|
||||||
explicit ZT_INLINE Lock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)) { _m->lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
explicit ZT_INLINE Lock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)) { _m->lock(); }
|
||||||
ZT_INLINE ~Lock() { _m->unlock(); }
|
ZT_INLINE ~Lock() { _m->unlock(); }
|
||||||
private:
|
private:
|
||||||
RWMutex *const _m;
|
RWMutex *const _m;
|
||||||
|
@ -97,8 +97,8 @@ public:
|
||||||
class RMaybeWLock
|
class RMaybeWLock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ZT_INLINE RMaybeWLock(RWMutex &m) noexcept : _m(&m),_w(false) { m.rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
explicit ZT_INLINE RMaybeWLock(RWMutex &m) noexcept : _m(&m),_w(false) { m.rlock(); }
|
||||||
explicit ZT_INLINE RMaybeWLock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)),_w(false) { _m->rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
explicit ZT_INLINE RMaybeWLock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)),_w(false) { _m->rlock(); }
|
||||||
ZT_INLINE void writing() noexcept { if (!_w) { _w = true; _m->runlock(); _m->lock(); } }
|
ZT_INLINE void writing() noexcept { if (!_w) { _w = true; _m->runlock(); _m->lock(); } }
|
||||||
ZT_INLINE void reading() noexcept { if (_w) { _w = false; _m->unlock(); _m->rlock(); } }
|
ZT_INLINE void reading() noexcept { if (_w) { _w = false; _m->unlock(); _m->rlock(); } }
|
||||||
ZT_INLINE ~RMaybeWLock() { if (_w) _m->unlock(); else _m->runlock(); }
|
ZT_INLINE ~RMaybeWLock() { if (_w) _m->unlock(); else _m->runlock(); }
|
||||||
|
@ -108,7 +108,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ZT_INLINE RWMutex(const RWMutex &) noexcept {} // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
ZT_INLINE RWMutex(const RWMutex &) noexcept {}
|
||||||
ZT_INLINE const RWMutex &operator=(const RWMutex &) noexcept { return *this; }
|
ZT_INLINE const RWMutex &operator=(const RWMutex &) noexcept { return *this; }
|
||||||
|
|
||||||
pthread_rwlock_t _mh;
|
pthread_rwlock_t _mh;
|
||||||
|
|
Loading…
Add table
Reference in a new issue