diff --git a/.travis.yml b/.travis.yml index 9190db65..fad93a84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,27 +29,27 @@ matrix: - ls -l /tmp/p2p-packages after_success: - bash <(curl -s https://codecov.io/bash) - deploy: - - provider: script - script: /tmp/p2p-packages/deploy.sh bin/p2p dev - skip_cleanup: true - on: - branch: dev - - provider: script - script: /tmp/p2p-packages/deploy.sh /tmp/p2p-packages/subutai-p2p-dev.deb dev - skip_cleanup: true - on: - branch: dev - - provider: script - script: /tmp/p2p-packages/deploy.sh bin/p2p master - skip_cleanup: true - on: - branch: master - - provider: script - script: /tmp/p2p-packages/deploy.sh bin/p2p HEAD - skip_cleanup: true - on: - tags: true +# deploy: +# - provider: script +# script: /tmp/p2p-packages/deploy.sh bin/p2p dev +# skip_cleanup: true +# on: +# branch: dev +# - provider: script +# script: /tmp/p2p-packages/deploy.sh /tmp/p2p-packages/subutai-p2p-dev.deb dev +# skip_cleanup: true +# on: +# branch: dev +# - provider: script +# script: /tmp/p2p-packages/deploy.sh bin/p2p master +# skip_cleanup: true +# on: +# branch: master +# - provider: script +# script: /tmp/p2p-packages/deploy.sh bin/p2p HEAD +# skip_cleanup: true +# on: +# tags: true - os: osx before_install: @@ -64,27 +64,27 @@ matrix: then (mv /tmp/p2p-packages/darwin/p2p.pkg /tmp/subutai-p2p.pkg) ; else (mv /tmp/p2p-packages/darwin/p2p.pkg /tmp/subutai-p2p-$TRAVIS_BRANCH.pkg) ; fi - deploy: - - provider: script - script: /tmp/p2p-packages/deploy.sh bin/p2p_osx dev - skip_cleanup: true - on: - branch: dev - - provider: script - script: /tmp/p2p-packages/deploy.sh /tmp/subutai-p2p-dev.pkg dev - skip_cleanup: true - on: - branch: dev - - provider: script - script: /tmp/p2p-packages/deploy.sh bin/p2p_osx master - skip_cleanup: true - on: - branch: master - - provider: script - script: /tmp/p2p-packages/deploy.sh bin/p2p_osx HEAD - skip_cleanup: true - on: - tags: true +# deploy: +# - provider: script +# script: /tmp/p2p-packages/deploy.sh bin/p2p_osx dev +# skip_cleanup: true +# on: +# branch: dev +# - provider: script +# script: /tmp/p2p-packages/deploy.sh /tmp/subutai-p2p-dev.pkg dev +# skip_cleanup: true +# on: +# branch: dev +# - provider: script +# script: /tmp/p2p-packages/deploy.sh bin/p2p_osx master +# skip_cleanup: true +# on: +# branch: master +# - provider: script +# script: /tmp/p2p-packages/deploy.sh bin/p2p_osx HEAD +# skip_cleanup: true +# on: +# tags: true branches: only: diff --git a/Jenkinsfile b/Jenkinsfile index 2607effe..77bf4bfa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,28 +12,18 @@ dhtSrv = "dht" switch (env.BRANCH_NAME) { case ~/master/: - cdnHost = "mastercdn.subutai.io"; dhtHost = "eu0.mastercdn.subutai.io:6881" dhtSrv = "masterdht" p2p_log_level = "DEBUG" break; case ~/dev/: - cdnHost = "devcdn.subutai.io"; dhtHost = "eu0.devcdn.subutai.io:6881"; dhtSrv = "devdht" gitcmd = "git checkout -B dev && git pull origin dev" p2p_log_level = "DEBUG" break; - case ~/sysnet/: - cdnHost = "sysnetcdn.subutai.io"; - dhtHost = "eu0.sysnetcdn.subutai.io:6881"; - dhtSrv = "sysnetdht" - gitcmd = "git checkout -B sysnet && git pull origin sysnet " - p2p_log_level = "TRACE" - break; default: - cdnHost = "cdn.subutai.io"; dhtHost = "eu0.cdn.subutai.io:6881" dhtSrv = "dht" break; @@ -79,7 +69,6 @@ try { """ /* stash p2p binary to use it in next node() */ - stash includes: 'bin/p2p', name: 'p2p' stash includes: 'bin/p2p.exe', name: 'p2p.exe' stash includes: 'bin/p2p_osx', name: 'p2p_osx' stash includes: 'upload-ipfs.sh', name: 'upload-ipfs.sh' @@ -99,95 +88,24 @@ try { */ if (env.BRANCH_NAME == 'dev' || env.BRANCH_NAME == 'master') { node("deb") { - /* Upload builed p2p artifacts to kurjun */ + /* Upload builed p2p artifacts to CDN */ deleteDir() - stage("Upload p2p binaries to kurjun") + stage("Upload p2p binaries to CDN") /* Get subutai binary from stage and push it to same branch of subos repo */ - notifyBuildDetails = "\nFailed on Stage - Upload p2p binaries to kurjun" - - /* cdn auth creadentials */ - String url = "https://${cdnHost}:8338/kurjun/rest" - String user = "jenkins" - def authID = sh (script: """ - set +x - curl -s -k ${url}/auth/token?user=${user} | gpg --clearsign --no-tty - """, returnStdout: true) - def token = sh (script: """ - set +x - curl -s -k -Fmessage=\"${authID}\" -Fuser=${user} ${url}/auth/token - """, returnStdout: true) + notifyBuildDetails = "\nFailed on Stage - Upload p2p binaries to CDN" /* upload p2p */ - unstash 'p2p' - unstash 'upload-ipfs.sh' - /* get p2p version */ - String p2pVersion = sh (script: """ - set +x - ./bin/p2p -v | cut -d " " -f 3 | tr -d '\n' - """, returnStdout: true) - if (env.BRANCH_NAME == 'dev' || env.BRANCH_NAME == 'master') { - String responseP2P = sh (script: """ - set +x - curl -s -k ${url}/raw/info?name=p2p - """, returnStdout: true) - sh """ - set +x - ./upload-ipfs.sh ${env.BRANCH_NAME} Linux - curl -s -k -H "token: ${token}" -Ffile=@bin/p2p -Fversion=${p2pVersion} ${url}/raw/upload - """ - /* delete old p2p */ - - if (responseP2P != "Not found") { - def jsonp2p = jsonParse(responseP2P) - sh """ - set +x - curl -s -k -X DELETE ${url}/raw/delete?id=${jsonp2p[0]["id"]}'&'token=${token} - """ - } - } - - /* upload p2p.exe */ unstash 'p2p.exe' - String responseP2Pexe = sh (script: """ - set +x - curl -s -k ${url}/raw/info?name=p2p.exe - """, returnStdout: true) - sh """ - set +x - ./upload-ipfs.sh ${env.BRANCH_NAME} MSYS_NT-10.0 - curl -s -k -H "token: ${token}" -Ffile=@bin/p2p.exe -Fversion=${p2pVersion} ${url}/raw/upload - """ - /* delete old p2p.exe */ - if (responseP2Pexe != "Not found") { - def jsonp2pexe = jsonParse(responseP2Pexe) - sh """ - set +x - curl -s -k -X DELETE ${url}/raw/delete?id=${jsonp2pexe[0]["id"]}'&'token=${token} - """ - } - - /* upload p2p_osx */ unstash 'p2p_osx' + unstash 'upload-ipfs.sh' if (env.BRANCH_NAME == 'dev' || env.BRANCH_NAME == 'master') { - String responseP2Posx = sh (script: """ - set +x - curl -s -k ${url}/raw/info?name=p2p_osx - """, returnStdout: true) sh """ set +x + ./upload-ipfs.sh ${env.BRANCH_NAME} MSYS_NT-10.0 ./upload-ipfs.sh ${env.BRANCH_NAME} Darwin - curl -s -k -H "token: ${token}" -Ffile=@bin/p2p_osx -Fversion=${p2pVersion} ${url}/raw/upload """ - /* delete old p2p */ - if (responseP2Posx != "Not found") { - def jsonp2posx = jsonParse(responseP2Posx) - sh """ - set +x - curl -s -k -X DELETE ${url}/raw/delete?id=${jsonp2posx[0]["id"]}'&'token=${token} - """ - } } } @@ -246,6 +164,7 @@ try { notifyBuildDetails = "\nFailed on Stage - Upload" sh """ cd ${CWD} + ./upload-ipfs.sh ${env.BRANCH_NAME} Linux touch uploading_agent scp uploading_agent subutai*.deb dak@debup.subutai.io:incoming/${env.BRANCH_NAME}/ ssh dak@debup.subutai.io sh /var/reprepro/scripts/scan-incoming.sh ${env.BRANCH_NAME} agent @@ -259,7 +178,6 @@ try { ${gitcmd} cp ${CWD}/subutai*.deb . ./upload-ipfs.sh ${env.BRANCH_NAME} - ./upload.sh debian ${env.BRANCH_NAME} subutai*.deb """ } @@ -275,7 +193,7 @@ try { rm -rf /tmp/p2p-packaging git clone git@github.com:optdyn/p2p-packaging.git /tmp/p2p-packaging cd /tmp/p2p-packaging - curl -fsSLk https://eu0.${env.BRANCH_NAME}cdn.subutai.io:8338/kurjun/rest/raw/get?name=p2p_osx -o /tmp/p2p-packaging/darwin/p2p_osx + curl -fsSLk 'https://${env.BRANCH_NAME}bazaar.subutai.io/rest/v1/cdn/raw?name=p2p-${env.BRANCH_NAME}_osx&download&latest' -o /tmp/p2p-packaging/darwin/p2p_osx chmod +x /tmp/p2p-packaging/darwin/p2p_osx /tmp/p2p-packaging/darwin/pack.sh /tmp/p2p-packaging/darwin/p2p_osx ${env.BRANCH_NAME} """ @@ -284,7 +202,6 @@ try { sh """ /tmp/p2p-packaging/./upload-ipfs.sh ${env.BRANCH_NAME} - /tmp/p2p-packaging/upload.sh darwin ${env.BRANCH_NAME} /tmp/p2p-packaging/darwin/p2p.pkg """ } } // If branch == master @@ -301,12 +218,11 @@ try { echo git clone git@github.com:optdyn/p2p-packaging.git /c/tmp/p2p-packaging >> c:\\tmp\\p2p-win.do echo cd /c/tmp/p2p-packaging >> c:\\tmp\\p2p-win.do echo git checkout ${env.BRANCH_NAME} >> c:\\tmp\\p2p-win.do - echo curl -fsSLk https://eu0.${env.BRANCH_NAME}cdn.subutai.io:8338/kurjun/rest/raw/get?name=p2p.exe -o /c/tmp/p2p-packaging/p2p.exe >> c:\\tmp\\p2p-win.do + echo curl -fsSLk "https://${env.BRANCH_NAME}bazaar.subutai.io/rest/v1/cdn/raw?name=p2p-${env.BRANCH_NAME}.exe&download&latest" -o /c/tmp/p2p-packaging/p2p.exe >> c:\\tmp\\p2p-win.do echo curl -fsSLk https://eu0.cdn.subutai.io:8338/kurjun/rest/raw/get?name=tap-windows-9.21.2.exe -o /c/tmp/p2p-packaging/tap-windows-9.21.2.exe >> c:\\tmp\\p2p-win.do echo sed -i -e "s/{VERSION_PLACEHOLDER}/${global_version}/g" /c/tmp/p2p-packaging/windows/P2PInstaller/P2PInstaller.vdproj >> c:\\tmp\\p2p-win.do echo sed -i -e "s/PRODUCT_CODE_PLACEHOLDER/${product_code}/g" /c/tmp/p2p-packaging/windows/P2PInstaller/P2PInstaller.vdproj >> c:\\tmp\\p2p-win.do - echo /c/tmp/p2p-packaging/upload.sh windows ${env.BRANCH_NAME} /c/tmp/p2p-packaging/windows/P2PInstaller/Release/P2PInstaller.msi > c:\\tmp\\p2p-win-upload.do echo /c/tmp/p2p-packaging/upload-ipfs.sh ${env.BRANCH_NAME} >> c:\\tmp\\p2p-win-upload.do echo call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\Tools\\VsDevCmd.bat" > c:\\tmp\\p2p-pack.bat diff --git a/lib/dht.go b/lib/dht.go index 2aebf416..744e2319 100644 --- a/lib/dht.go +++ b/lib/dht.go @@ -26,24 +26,22 @@ type RemotePeerState struct { // DHTClient is a main structure of a DHT client type DHTClient struct { - Routers string // Comma-separated list of bootstrap nodes - NetworkHash string // Saved network hash - ID string // Current instance ID - FailedRouters []string // List of routes that we failed to connect to - Connections []*net.TCPConn // TCP connections to bootstrap nodes - LocalPort int // UDP port number used by this instance - RemotePort int // UDP port number reported by echo server - Forwarders []Forwarder // List of worwarders - TCPCallbacks map[protocol.DHTPacketType]dhtCallback // Callbacks for incoming packets - Mode OperatingMode // DHT Client mode ??? - IPList []net.IP // List of network active interfaces - IP net.IP // IP of local interface received from DHCP or specified manually - Network *net.IPNet // Network information about current network. Used to inform p2p about mask for interface - Connected bool // Whether connection with bootstrap nodes established or not - //isShutdown bool // Whether DHT shutting down or not - LastUpdate time.Time // When last `find` packet was sent - OutboundIP net.IP // Outbound IP - ListenerIsRunning bool // True if listener is runnning + Routers string // Comma-separated list of bootstrap nodes + NetworkHash string // Saved network hash + ID string // Current instance ID + FailedRouters []string // List of routes that we failed to connect to + LocalPort int // UDP port number used by this instance + RemotePort int // UDP port number reported by echo server + Forwarders []Forwarder // List of worwarders + TCPCallbacks map[protocol.DHTPacketType]dhtCallback // Callbacks for incoming packets + Mode OperatingMode // DHT Client mode ??? + IPList []net.IP // List of network active interfaces + IP net.IP // IP of local interface received from DHCP or specified manually + Network *net.IPNet // Network information about current network. Used to inform p2p about mask for interface + Connected bool // Whether connection with bootstrap nodes established or not + LastUpdate time.Time // When last `find` packet was sent + OutboundIP net.IP // Outbound IP + ListenerIsRunning bool // True if listener is runnning IncomingData chan *protocol.DHTPacket OutgoingData chan *protocol.DHTPacket } diff --git a/lib/dht_test.go b/lib/dht_test.go index 44b52720..8a213429 100644 --- a/lib/dht_test.go +++ b/lib/dht_test.go @@ -595,7 +595,6 @@ func TestDHTClient_WaitID(t *testing.T) { NetworkHash: tt.fields.NetworkHash, ID: tt.fields.ID, FailedRouters: tt.fields.FailedRouters, - Connections: tt.fields.Connections, LocalPort: tt.fields.LocalPort, RemotePort: tt.fields.RemotePort, Forwarders: tt.fields.Forwarders, @@ -659,7 +658,6 @@ func TestDHTClient_RegisterProxy(t *testing.T) { NetworkHash: tt.fields.NetworkHash, ID: tt.fields.ID, FailedRouters: tt.fields.FailedRouters, - Connections: tt.fields.Connections, LocalPort: tt.fields.LocalPort, RemotePort: tt.fields.RemotePort, Forwarders: tt.fields.Forwarders, @@ -722,7 +720,6 @@ func TestDHTClient_ReportLoad(t *testing.T) { NetworkHash: tt.fields.NetworkHash, ID: tt.fields.ID, FailedRouters: tt.fields.FailedRouters, - Connections: tt.fields.Connections, LocalPort: tt.fields.LocalPort, RemotePort: tt.fields.RemotePort, Forwarders: tt.fields.Forwarders, diff --git a/lib/net.go b/lib/net.go index b0b11dba..65a90801 100644 --- a/lib/net.go +++ b/lib/net.go @@ -125,11 +125,13 @@ type Network struct { disposed bool } -// Stop will terminate packet reader -func (uc *Network) Stop() error { +// Close will terminate packet reader +func (uc *Network) Close() error { uc.disposed = true if uc.conn != nil { - return uc.conn.Close() + err := uc.conn.Close() + uc.conn = nil + return err } return fmt.Errorf("Nil Connection") } diff --git a/lib/net_test.go b/lib/net_test.go index 77ab0d15..c324af25 100644 --- a/lib/net_test.go +++ b/lib/net_test.go @@ -94,7 +94,7 @@ func TestP2PMessageHeader_Serialize(t *testing.T) { fields fields want []byte }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -122,7 +122,7 @@ func TestP2PMessage_Serialize(t *testing.T) { fields fields want []byte }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -147,7 +147,7 @@ func TestP2PMessageFromBytes(t *testing.T) { want *P2PMessage wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -547,7 +547,7 @@ func TestNetwork_Stop(t *testing.T) { inBuffer: tt.fields.inBuffer, disposed: tt.fields.disposed, } - if err := uc.Stop(); (err != nil) != tt.wantErr { + if err := uc.Close(); (err != nil) != tt.wantErr { t.Errorf("Network.Stop() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/lib/p2p.go b/lib/p2p.go index 95e30e82..13fa393b 100644 --- a/lib/p2p.go +++ b/lib/p2p.go @@ -602,7 +602,7 @@ func (p *PeerToPeer) Close() error { if err != nil { Log(Error, "Failed to stop DHT: %s", err) } - p.UDPSocket.Stop() + p.UDPSocket.Close() if p.Interface != nil { err := p.Interface.Close() diff --git a/upload-ipfs.sh b/upload-ipfs.sh index 5834b373..585e9232 100755 --- a/upload-ipfs.sh +++ b/upload-ipfs.sh @@ -41,28 +41,31 @@ case $OS in Linux) BASENAME="p2p" BIN_EXT="" + BIN_DIR="p2p/debian/subutai-p2p/usr/bin" ;; MSYS_NT-10.0) BASENAME="p2p.exe" BIN_EXT=".exe" + BIN_DIR="bin" ;; Darwin) BASENAME="p2p_osx" BIN_EXT="_osx" + BIN_DIR="bin" ;; esac case $BRANCH in dev) BINNAME="p2p-dev$BIN_EXT" - cd bin + cd $BIN_DIR cp $BASENAME $BINNAME IPFSURL=https://devbazaar.subutai.io upload_ipfs $BINNAME $IPFSURL ;; master) BINNAME="p2p-master$BIN_EXT" - cd bin + cd $BIN_DIR cp $BASENAME $BINNAME IPFSURL=https://masterbazaar.subutai.io upload_ipfs $BINNAME $IPFSURL @@ -71,7 +74,7 @@ case $BRANCH in BINNAME="p2p$BIN_EXT" if [ $OS = Linux ] || [$OS = MSYS_NT-10.0 ] then - cd bin + cd $BIN_DIR cp $BASENAME $BINNAME IPFSURL=https://bazaar.subutai.io upload_ipfs $BINNAME $IPFSURL @@ -81,7 +84,7 @@ case $BRANCH in BINNAME="subutai-p2p$PKG_EXT" if [ $OS = Linux ] || [$OS = MSYS_NT-10.0 ] then - cd bin + cd $BIN_DIR cp $BASENAME $BINNAME IPFSURL=https://bazaar.subutai.io upload_ipfs $BINNAME $IPFSURL