mirror of
https://github.com/xubiaolin/docker-zerotier-planet.git
synced 2025-01-22 12:48:14 -05:00
init
This commit is contained in:
commit
430edf9c6e
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
8
.idea/docker-zerotier-planet.iml
generated
Normal file
8
.idea/docker-zerotier-planet.iml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/docker-zerotier-planet.iml" filepath="$PROJECT_DIR$/.idea/docker-zerotier-planet.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
42
Dockerfile
Normal file
42
Dockerfile
Normal file
@ -0,0 +1,42 @@
|
||||
FROM centos:7
|
||||
|
||||
WORKDIR /opt
|
||||
COPY . /var/lib/zerotier-one/
|
||||
VOLUME ["/opt","/var/lib/zerotier-one"]
|
||||
EXPOSE 9993
|
||||
|
||||
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && \
|
||||
yum update -y && \
|
||||
yum install git make gcc gcc-c++ python3 wget -y && \
|
||||
yum install centos-release-scl -y &&\
|
||||
yum install devtoolset-8 -y &&\
|
||||
|
||||
# 编译服务
|
||||
cd /opt && \
|
||||
git clone https://github.com.cnpmjs.org/zerotier/ZeroTierOne.git && \
|
||||
cd ZeroTierOne && \
|
||||
make && \
|
||||
make install && \
|
||||
|
||||
# 配置moon
|
||||
cd /var/lib/zerotier-one && \
|
||||
zerotier-idtool generate identity.public identity.secret &&\
|
||||
zerotier-idtool initmoon identity.public >> moon.json &&\
|
||||
|
||||
# 配置补丁
|
||||
cd /var/lib/zerotier-one && \
|
||||
python3 patch.py && \
|
||||
zerotier-idtool genmoon moon.json && \
|
||||
mkdir moons.d && cp ./*.moon ./moons.d &&\
|
||||
rm -rf planet &&\
|
||||
|
||||
# 编译新的plane
|
||||
cd /opt/ZeroTierOne/attic/world/ && \
|
||||
sh build.sh &&\
|
||||
mv world.bin /var/lib/zerotier-one/planet
|
||||
|
||||
CMD [ "bash","run.sh" ]
|
||||
|
||||
|
||||
|
||||
|
119
mkworld.cpp
Normal file
119
mkworld.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This utility makes the World from the configuration specified below.
|
||||
* It probably won't be much use to anyone outside ZeroTier, Inc. except
|
||||
* for testing and experimentation purposes.
|
||||
*
|
||||
* If you want to make your own World you must edit this file.
|
||||
*
|
||||
* When run, it expects two files in the current directory:
|
||||
*
|
||||
* previous.c25519 - key pair to sign this world (key from previous world)
|
||||
* current.c25519 - key pair whose public key should be embedded in this world
|
||||
*
|
||||
* If these files do not exist, they are both created with the same key pair
|
||||
* and a self-signed initial World is born.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <node/Constants.hpp>
|
||||
#include <node/World.hpp>
|
||||
#include <node/C25519.hpp>
|
||||
#include <node/Identity.hpp>
|
||||
#include <node/InetAddress.hpp>
|
||||
#include <osdep/OSUtils.hpp>
|
||||
|
||||
using namespace ZeroTier;
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
std::string previous,current;
|
||||
if ((!OSUtils::readFile("previous.c25519",previous))||(!OSUtils::readFile("current.c25519",current))) {
|
||||
C25519::Pair np(C25519::generate());
|
||||
previous = std::string();
|
||||
previous.append((const char *)np.pub.data,ZT_C25519_PUBLIC_KEY_LEN);
|
||||
previous.append((const char *)np.priv.data,ZT_C25519_PRIVATE_KEY_LEN);
|
||||
current = previous;
|
||||
OSUtils::writeFile("previous.c25519",previous);
|
||||
OSUtils::writeFile("current.c25519",current);
|
||||
fprintf(stderr,"INFO: created initial world keys: previous.c25519 and current.c25519 (both initially the same)" ZT_EOL_S);
|
||||
}
|
||||
|
||||
if ((previous.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))||(current.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))) {
|
||||
fprintf(stderr,"FATAL: previous.c25519 or current.c25519 empty or invalid" ZT_EOL_S);
|
||||
return 1;
|
||||
}
|
||||
C25519::Pair previousKP;
|
||||
memcpy(previousKP.pub.data,previous.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
||||
memcpy(previousKP.priv.data,previous.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
||||
C25519::Pair currentKP;
|
||||
memcpy(currentKP.pub.data,current.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
||||
memcpy(currentKP.priv.data,current.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
||||
|
||||
// =========================================================================
|
||||
// EDIT BELOW HERE
|
||||
|
||||
std::vector<World::Root> roots;
|
||||
|
||||
const uint64_t id = ZT_WORLD_ID_EARTH;
|
||||
const uint64_t ts = 1567191349589ULL; // August 30th, 2019
|
||||
|
||||
//__PATCH_REPLACE__
|
||||
|
||||
// END WORLD DEFINITION
|
||||
// =========================================================================
|
||||
|
||||
fprintf(stderr,"INFO: generating and signing id==%llu ts==%llu" ZT_EOL_S,(unsigned long long)id,(unsigned long long)ts);
|
||||
|
||||
World nw = World::make(World::TYPE_PLANET,id,ts,currentKP.pub,roots,previousKP);
|
||||
|
||||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> outtmp;
|
||||
nw.serialize(outtmp,false);
|
||||
World testw;
|
||||
testw.deserialize(outtmp,0);
|
||||
if (testw != nw) {
|
||||
fprintf(stderr,"FATAL: serialization test failed!" ZT_EOL_S);
|
||||
return 1;
|
||||
}
|
||||
|
||||
OSUtils::writeFile("world.bin",std::string((const char *)outtmp.data(),outtmp.size()));
|
||||
fprintf(stderr,"INFO: world.bin written with %u bytes of binary world data." ZT_EOL_S,outtmp.size());
|
||||
|
||||
fprintf(stdout,ZT_EOL_S);
|
||||
fprintf(stdout,"#define ZT_DEFAULT_WORLD_LENGTH %u" ZT_EOL_S,outtmp.size());
|
||||
fprintf(stdout,"static const unsigned char ZT_DEFAULT_WORLD[ZT_DEFAULT_WORLD_LENGTH] = {");
|
||||
for(unsigned int i=0;i<outtmp.size();++i) {
|
||||
const unsigned char *d = (const unsigned char *)outtmp.data();
|
||||
if (i > 0)
|
||||
fprintf(stdout,",");
|
||||
fprintf(stdout,"0x%.2x",(unsigned int)d[i]);
|
||||
}
|
||||
fprintf(stdout,"};" ZT_EOL_S);
|
||||
|
||||
return 0;
|
||||
}
|
5
patch.json
Normal file
5
patch.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"stableEndpoints": [
|
||||
"81.70.255.9/9993"
|
||||
]
|
||||
}
|
51
patch.py
Normal file
51
patch.py
Normal file
@ -0,0 +1,51 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
def patch_moon():
|
||||
patch_data = dict()
|
||||
with open("patch.json", "r") as f:
|
||||
patch_data = json.load(f)
|
||||
|
||||
moon = dict()
|
||||
with open("moon.json", "r") as f:
|
||||
moon = json.load(f)
|
||||
|
||||
endpoint_patch = patch_data.get("stableEndpoints", [])
|
||||
if len(endpoint_patch) == 0:
|
||||
print("请配置endpoint!")
|
||||
exit(1)
|
||||
|
||||
moon["roots"][0]["stableEndpoints"] = endpoint_patch
|
||||
|
||||
with open("moon.json", "w+") as f:
|
||||
f.write(json.dumps(moon))
|
||||
|
||||
|
||||
def patch_world():
|
||||
moon = dict()
|
||||
|
||||
file_moon = open("moon.json", "r")
|
||||
moon = json.load(file_moon)
|
||||
file_moon.close()
|
||||
|
||||
middle = '''
|
||||
//China
|
||||
roots.push_back(World::Root());
|
||||
roots.back().identity = Identity("{}");'''.format(moon["roots"][0]["identity"])
|
||||
|
||||
for i in moon["roots"][0]["stableEndpoints"]:
|
||||
middle += '\n roots.back().stableEndpoints.push_back(InetAddress("{}"));'.format(i)
|
||||
|
||||
with open("mkworld.cpp", "r") as cpp:
|
||||
code = "".join(cpp.readlines())
|
||||
|
||||
with open("mknewworld.cpp", "w+") as cpp:
|
||||
code = code.replace(" //__PATCH_REPLACE__", middle)
|
||||
print(code)
|
||||
cpp.write(code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
patch_moon()
|
||||
patch_world()
|
Loading…
Reference in New Issue
Block a user