mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Write a zerotier-one.port file to the home path to make CLI easy to write, and do a backward compatiable CLI in bash instead of as part of the executable.
This commit is contained in:
parent
21a7e774bb
commit
4e5d2d2c72
5 changed files with 10 additions and 31 deletions
|
@ -60,7 +60,6 @@ all: one
|
||||||
one: $(OBJS) one.o
|
one: $(OBJS) one.o
|
||||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LIBS)
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LIBS)
|
||||||
$(STRIP) zerotier-one
|
$(STRIP) zerotier-one
|
||||||
ln -sf zerotier-one zerotier-cli
|
|
||||||
ln -sf zerotier-one zerotier-idtool
|
ln -sf zerotier-one zerotier-idtool
|
||||||
|
|
||||||
selftest: $(OBJS) selftest.o
|
selftest: $(OBJS) selftest.o
|
||||||
|
@ -72,7 +71,7 @@ selftest: $(OBJS) selftest.o
|
||||||
# ./buildinstaller.sh
|
# ./buildinstaller.sh
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o build-* zerotier-* ZeroTierOneInstaller-*
|
rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o build-* zerotier-one zerotier-idtool zerotier-selftest ZeroTierOneInstaller-*
|
||||||
|
|
||||||
debug: FORCE
|
debug: FORCE
|
||||||
make -j 4 ZT_DEBUG=1
|
make -j 4 ZT_DEBUG=1
|
||||||
|
|
|
@ -66,7 +66,6 @@ all: one
|
||||||
one: $(OBJS) one.o
|
one: $(OBJS) one.o
|
||||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LIBS)
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LIBS)
|
||||||
$(STRIP) zerotier-one
|
$(STRIP) zerotier-one
|
||||||
ln -sf zerotier-one zerotier-cli
|
|
||||||
ln -sf zerotier-one zerotier-idtool
|
ln -sf zerotier-one zerotier-idtool
|
||||||
|
|
||||||
selftest: $(OBJS) selftest.o
|
selftest: $(OBJS) selftest.o
|
||||||
|
@ -77,7 +76,7 @@ installer: one FORCE
|
||||||
./buildinstaller.sh
|
./buildinstaller.sh
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o zerotier-* build-* ZeroTierOneInstaller-* *.deb *.rpm
|
rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o zerotier-one zerotier-idtool zerotier-selftest build-* ZeroTierOneInstaller-* *.deb *.rpm
|
||||||
|
|
||||||
debug: FORCE
|
debug: FORCE
|
||||||
make -j 4 ZT_DEBUG=1
|
make -j 4 ZT_DEBUG=1
|
||||||
|
|
|
@ -55,7 +55,6 @@ all: one
|
||||||
one: $(OBJS) one.o
|
one: $(OBJS) one.o
|
||||||
$(CXX) $(CXXFLAGS) -o zerotier-one $(OBJS) one.o $(LIBS)
|
$(CXX) $(CXXFLAGS) -o zerotier-one $(OBJS) one.o $(LIBS)
|
||||||
$(STRIP) zerotier-one
|
$(STRIP) zerotier-one
|
||||||
ln -sf zerotier-one zerotier-cli
|
|
||||||
ln -sf zerotier-one zerotier-idtool
|
ln -sf zerotier-one zerotier-idtool
|
||||||
|
|
||||||
selftest: $(OBJS) selftest.o
|
selftest: $(OBJS) selftest.o
|
||||||
|
@ -76,7 +75,7 @@ selftest: $(OBJS) selftest.o
|
||||||
# $(CODESIGN) -vvv "build-ZeroTierUI-release/ZeroTier One.app"
|
# $(CODESIGN) -vvv "build-ZeroTierUI-release/ZeroTier One.app"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf *.dSYM build-* *.pkg *.dmg *.o node/*.o controller/*.o service/*.o osdep/*.o ext/http-parser/*.o ext/lz4/*.o zerotier-* ZeroTierOneInstaller-*
|
rm -rf *.dSYM build-* *.pkg *.dmg *.o node/*.o controller/*.o service/*.o osdep/*.o ext/http-parser/*.o ext/lz4/*.o zerotier-one zerotier-idtool zerotier-selftest ZeroTierOneInstaller-*
|
||||||
|
|
||||||
# For our use -- builds official signed binary, packages in installer and download DMG
|
# For our use -- builds official signed binary, packages in installer and download DMG
|
||||||
official: FORCE
|
official: FORCE
|
||||||
|
|
26
one.cpp
26
one.cpp
|
@ -75,18 +75,6 @@ using namespace ZeroTier;
|
||||||
|
|
||||||
static OneService *volatile zt1Service = (OneService *)0;
|
static OneService *volatile zt1Service = (OneService *)0;
|
||||||
|
|
||||||
/****************************************************************************/
|
|
||||||
/* zerotier-cli personality */
|
|
||||||
/****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
int cli(int argc, _TCHAR* argv[])
|
|
||||||
#else
|
|
||||||
int cli(int argc,char **argv)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* zerotier-idtool personality */
|
/* zerotier-idtool personality */
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
@ -435,7 +423,7 @@ static void printHelp(const char *cn,FILE *out)
|
||||||
{
|
{
|
||||||
fprintf(out,"ZeroTier One version %d.%d.%d"ZT_EOL_S"(c)2011-2015 ZeroTier, Inc."ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION);
|
fprintf(out,"ZeroTier One version %d.%d.%d"ZT_EOL_S"(c)2011-2015 ZeroTier, Inc."ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION);
|
||||||
fprintf(out,"Licensed under the GNU General Public License v3"ZT_EOL_S""ZT_EOL_S);
|
fprintf(out,"Licensed under the GNU General Public License v3"ZT_EOL_S""ZT_EOL_S);
|
||||||
fprintf(out,"Usage: %s [-switches] [home directory] [-q <query>]"ZT_EOL_S""ZT_EOL_S,cn);
|
fprintf(out,"Usage: %s [-switches] [home directory]"ZT_EOL_S""ZT_EOL_S,cn);
|
||||||
fprintf(out,"Available switches:"ZT_EOL_S);
|
fprintf(out,"Available switches:"ZT_EOL_S);
|
||||||
fprintf(out," -h - Display this help"ZT_EOL_S);
|
fprintf(out," -h - Display this help"ZT_EOL_S);
|
||||||
fprintf(out," -v - Show version"ZT_EOL_S);
|
fprintf(out," -v - Show version"ZT_EOL_S);
|
||||||
|
@ -444,7 +432,6 @@ static void printHelp(const char *cn,FILE *out)
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S);
|
fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S);
|
||||||
#endif // __UNIX_LIKE__
|
#endif // __UNIX_LIKE__
|
||||||
fprintf(out," -q - Send a query to a running service (zerotier-cli)"ZT_EOL_S);
|
|
||||||
fprintf(out," -i - Generate and manage identities (zerotier-idtool)"ZT_EOL_S);
|
fprintf(out," -i - Generate and manage identities (zerotier-idtool)"ZT_EOL_S);
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
fprintf(out," -C - Run from command line instead of as service (Windows)"ZT_EOL_S);
|
fprintf(out," -C - Run from command line instead of as service (Windows)"ZT_EOL_S);
|
||||||
|
@ -495,8 +482,6 @@ int main(int argc,char **argv)
|
||||||
#endif
|
#endif
|
||||||
#endif // __WINDOWS__
|
#endif // __WINDOWS__
|
||||||
|
|
||||||
if ((strstr(argv[0],"zerotier-cli"))||(strstr(argv[0],"ZEROTIER-CLI")))
|
|
||||||
return cli(argc,argv);
|
|
||||||
if ((strstr(argv[0],"zerotier-idtool"))||(strstr(argv[0],"ZEROTIER-IDTOOL")))
|
if ((strstr(argv[0],"zerotier-idtool"))||(strstr(argv[0],"ZEROTIER-IDTOOL")))
|
||||||
return idtool(argc,argv);
|
return idtool(argc,argv);
|
||||||
|
|
||||||
|
@ -516,9 +501,6 @@ int main(int argc,char **argv)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't': // TCP port -- ignore, since we now bind to both UDP and TCP on the same port
|
|
||||||
break;
|
|
||||||
|
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
case 'd': // Run in background as daemon
|
case 'd': // Run in background as daemon
|
||||||
runAsDaemon = true;
|
runAsDaemon = true;
|
||||||
|
@ -541,12 +523,6 @@ int main(int argc,char **argv)
|
||||||
printf("%d.%d.%d"ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION);
|
printf("%d.%d.%d"ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case 'q': // Invoke cli personality
|
|
||||||
if (argv[i][2]) {
|
|
||||||
printHelp(argv[0],stdout);
|
|
||||||
return 0;
|
|
||||||
} else return cli(argc,argv);
|
|
||||||
|
|
||||||
case 'i': // Invoke idtool personality
|
case 'i': // Invoke idtool personality
|
||||||
if (argv[i][2]) {
|
if (argv[i][2]) {
|
||||||
printHelp(argv[0],stdout);
|
printHelp(argv[0],stdout);
|
||||||
|
|
|
@ -131,6 +131,7 @@ class OneServiceImpl : public OneService
|
||||||
public:
|
public:
|
||||||
OneServiceImpl(const char *hp,unsigned int port,NetworkController *master,const char *overrideRootTopology) :
|
OneServiceImpl(const char *hp,unsigned int port,NetworkController *master,const char *overrideRootTopology) :
|
||||||
_homePath((hp) ? hp : "."),
|
_homePath((hp) ? hp : "."),
|
||||||
|
_port(port),
|
||||||
_phy(this,true),
|
_phy(this,true),
|
||||||
_master(master),
|
_master(master),
|
||||||
_overrideRootTopology((overrideRootTopology) ? overrideRootTopology : ""),
|
_overrideRootTopology((overrideRootTopology) ? overrideRootTopology : ""),
|
||||||
|
@ -160,6 +161,10 @@ public:
|
||||||
in6.sin6_port = in4.sin_port;
|
in6.sin6_port = in4.sin_port;
|
||||||
_v6UdpSocket = _phy.udpBind((const struct sockaddr *)&in6,this,131072);
|
_v6UdpSocket = _phy.udpBind((const struct sockaddr *)&in6,this,131072);
|
||||||
_v6TcpListenSocket = _phy.tcpListen((const struct sockaddr *)&in6,this);
|
_v6TcpListenSocket = _phy.tcpListen((const struct sockaddr *)&in6,this);
|
||||||
|
|
||||||
|
char portstr[64];
|
||||||
|
Utils::snprintf(portstr,sizeof(portstr),"%u",port);
|
||||||
|
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "zerotier-one.port").c_str(),std::string(portstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~OneServiceImpl()
|
virtual ~OneServiceImpl()
|
||||||
|
@ -632,6 +637,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string _homePath;
|
const std::string _homePath;
|
||||||
|
unsigned int _port;
|
||||||
Phy<OneServiceImpl *> _phy;
|
Phy<OneServiceImpl *> _phy;
|
||||||
NetworkController *_master;
|
NetworkController *_master;
|
||||||
std::string _overrideRootTopology;
|
std::string _overrideRootTopology;
|
||||||
|
|
Loading…
Add table
Reference in a new issue