diff --git a/go.mod b/go.mod index 27375bb..eaafd80 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/julienschmidt/httprouter v1.3.0 github.com/lithdew/bytesutil v0.0.0-20200409052507-d98389230a59 github.com/lithdew/kademlia v0.0.0-20200607181215-ff07ba2ac940 - github.com/lithdew/monte v0.0.0-20200612163155-688f7a476468 + github.com/lithdew/monte v0.0.0-20200613034704-f6d482652dc3 github.com/stretchr/testify v1.6.0 // indirect golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 // indirect diff --git a/go.sum b/go.sum index 6c38e05..bd638e8 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,12 @@ github.com/lithdew/monte v0.0.0-20200612162118-d9ef724a278f h1:ePrvQ/QMnHVDjWfan github.com/lithdew/monte v0.0.0-20200612162118-d9ef724a278f/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc= github.com/lithdew/monte v0.0.0-20200612163155-688f7a476468 h1:uVJAVZL+BulMCLaRtjVwp4jH2d6IIls+QjkIZdddCvY= github.com/lithdew/monte v0.0.0-20200612163155-688f7a476468/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc= +github.com/lithdew/monte v0.0.0-20200613022731-a95a5517aea6 h1:pGNp1mgfiRnNTqCxnu7zPna8WT4LFVOoUiiUV5nlEq4= +github.com/lithdew/monte v0.0.0-20200613022731-a95a5517aea6/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc= +github.com/lithdew/monte v0.0.0-20200613030909-f5e1611bfa09 h1:bYiP8Cnf0SU5QHYLfaiRFeI/eFGLKfEPPxjU+VewUjw= +github.com/lithdew/monte v0.0.0-20200613030909-f5e1611bfa09/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc= +github.com/lithdew/monte v0.0.0-20200613034704-f6d482652dc3 h1:HzVVwsj110ohL9hkXlg0akWmbZLWKnjApiEy0oZao20= +github.com/lithdew/monte v0.0.0-20200613034704-f6d482652dc3/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc= github.com/lithdew/reliable v0.0.0-20200506103725-7df64908b057 h1:CBhKVPym/7ZzY7ascOG93XSTlJuqrmIU/Hd0UDHC1TA= github.com/lithdew/reliable v0.0.0-20200506103725-7df64908b057/go.mod h1:b9iSDHZ4DaCGpwhQdKsH0u61UancBXJMe0r8SCPKEEA= github.com/lithdew/seq v0.0.0-20200504083424-74d5d8117a05 h1:j1UtG8NYCupA5xUwQ/vrTf/zjuNlZ0D1n7UtM8LhS58= diff --git a/ts/main.js b/ts/main.js index 74a1325..4cd20c5 100644 --- a/ts/main.js +++ b/ts/main.js @@ -53,7 +53,7 @@ class Flatend { this.conn.on('data', this._data.bind(this)); this.conn.on('error', console.error); - this.conn.on('close', () => { + this.conn.once('close', () => { const reconnect = async () => { console.log(`Trying to reconnect to ${ip.toString(this.id.host, 12, 4)}:${this.id.port}. Sleeping for 1s.`); @@ -62,6 +62,8 @@ class Flatend { console.log(`Successfully connected to ${ip.toString(this.id.host, 12, 4)}:${this.id.port}.`); } catch (err) { + this.conn.destroy(err); + setTimeout(reconnect, 1000); } }; diff --git a/ts/monte.js b/ts/monte.js index 4ea4623..c90f842 100644 --- a/ts/monte.js +++ b/ts/monte.js @@ -149,7 +149,7 @@ class MonteSocket extends Duplex { } async request(req, timeout = 3000) { - const seq = this.counter === 0 ? 1 : this.counter++; + const seq = this.counter === 0 ? 1 : this.counter += 2; if (this.counter === 2 ** 32) this.counter = 0; const response = new Promise((resolve, reject) => { @@ -218,9 +218,7 @@ class MonteSocket extends Duplex { if (seq === 0 || this.pending.listenerCount(`${seq}`) === 0) { try { - if (!this.push({seq, frame})) { - this._paused = true; - } + this.push({seq, frame}); } catch (err) { this.emit("error", err); }