Skip to content

Commit

Permalink
Merge pull request #16 from AvadoDServer/0.0.49
Browse files Browse the repository at this point in the history
bump to 1.14.2 + service fixes
  • Loading branch information
sponnet authored Nov 29, 2024
2 parents 4a97063 + c88ee3f commit ea95980
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN yarn build


# FROM --platform=linux/amd64 ${ALPINE_IMAGE}:${ALPINE_VERSION}
FROM --platform=linux/amd64 zyclonite/zerotier
FROM --platform=linux/amd64 zyclonite/zerotier:1.14.2

# COPY --from=builder /src/zerotier-one /usr/sbin/

Expand Down
2 changes: 1 addition & 1 deletion build/monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"@babel/helper-create-class-features-plugin": "^7.22.9",
"assert": "^2.0.0",
"axios": "^1.4.0",
"axios": "^1.7.8",
"chokidar": "^3.5.3",
"express": "^4.18.2",
"nanorequest": "^5.0.0",
Expand Down
8 changes: 5 additions & 3 deletions build/monitor/routes-zt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ module.exports = (server, config) => {
console.log("Get network status");
console.log("fetch status");
const status = await config.ztController.status();
const info = await config.ztController.info();
// console.log("fetch info");
// const info = await config.ztController.info();
console.log("ok rcvg status", status.data);
const networkId = config.db.get("networkid");
const network = await config.ztController.getNetwork(networkId);
console.log("got network data");
let response = {
networkid: networkId,
network: network ? network.data : undefined,
status: status ? status.data : undefined,
info: info ? info.data : undefined,
// info: info ? info.data : undefined,
};
return res.send(response);
} catch (error) {
return res.send(500, e.message);
return res.send(500, error.message);
}
});

Expand Down
84 changes: 67 additions & 17 deletions build/monitor/zerotier-controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var assert = require('assert')
var request = require('nanorequest')
const axios = require('axios');
const http = require('http');


class Service {
constructor({ authToken, host = '127.0.0.1', port = 9993 }) {
constructor({ authToken, host = 'localhost', port = 9993 }) {
assert(
typeof authToken === 'string',
'We need an authToken to talk to the service.'
Expand All @@ -22,31 +24,80 @@ class Service {
headers: this._headers
}

this.authToken = authToken;

this.controller = this.controller.bind(this)
this.network = this.network.bind(this)
this._status = this._status.bind(this)

}

get(opts, cb) {
opts = {
method: 'get',
timeout: 2000,
url: opts.path,
baseURL: `http://${this.defaultOpts.host}:${this.defaultOpts.port}`,
headers: this.defaultOpts.headers
}
return axios.request(opts).then((r) => {
return r
})
}


get(opts) {
return new Promise((resolve, reject) => {
const options = {
hostname: this.defaultOpts.host,
port: this.defaultOpts.port,
path: opts.path,
method: 'GET',
headers: {
'X-ZT1-AUTH': this.authToken, // Custom header
},
};
console.log(`GET request`, options);
const req = http.request(options, (res) => {
let data = '';

// Collect response data chunks
res.on('data', (chunk) => {
data += chunk;
});

// Handle end of response
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
console.log(`http fetch returns`, data);
resolve({ data: JSON.parse(data) }); // Resolve with { data }
} else {
reject(
new Error(
`HTTP error! Status: ${res.statusCode}, Message: ${res.statusMessage}`
)
);
}
});
});

// Handle errors
req.on('error', (error) => {
reject(new Error(`Request error: ${error.message}`));
});

// Finalize the request
req.end();
});
}


// get(opts, cb) {
// opts = {
// method: 'get',
// url: `http://${this.defaultOpts.host}:${this.defaultOpts.port}${opts.path}`,
// headers: this.defaultOpts.headers
// }
// console.log(`get opts`, opts);
// return axios.request(opts).then((r) => {
// console.log(`get returns`, r);
// return r
// })
// }

post(opts, cb) {
opts = {
method: 'post',
timeout: 2000,
url: opts.path,
baseURL: `http://${this.defaultOpts.host}:${this.defaultOpts.port}`,
url: `http://${this.defaultOpts.host}:${this.defaultOpts.port}${opts.path}`,
headers: this.defaultOpts.headers,
data: opts.body
}
Expand All @@ -60,8 +111,7 @@ class Service {
opts = {
method: 'delete',
timeout: 2000,
url: opts.path,
baseURL: `http://${this.defaultOpts.host}:${this.defaultOpts.port}`,
url: `http://${this.defaultOpts.host}:${this.defaultOpts.port}${opts.path}`,
headers: this.defaultOpts.headers
}
return axios.request(opts).then((r) => {
Expand Down
2 changes: 1 addition & 1 deletion dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remoteconnect.avado.dnp.dappnode.eth",
"version": "0.0.34",
"version": "0.0.49",
"title": "Remote Access",
"description": "Remote Access",
"autoupdate": true,
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ networks:
services:
remoteconnect.avado.dnp.dappnode.eth:
container_name: DAppNodeCore-remoteconnect.avado.dnp.dappnode.eth
image: 'remoteconnect.avado.dnp.dappnode.eth:0.0.34'
image: 'remoteconnect.avado.dnp.dappnode.eth:0.0.49'
build: ./build
volumes:
- 'zt-data:/var/lib/zerotier-one'
Expand Down

0 comments on commit ea95980

Please sign in to comment.