etunnel 1.7.35 → 1.7.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -1
  3. data/lib/etunnel.rb +36 -8
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58d3acf5807d65563d747749daeb1e98ba8eaa5d3312e25923a21486e994096d
4
- data.tar.gz: 72c1dd64d6b955c2fa0b04119be7079e040caa98813cf7329fee602842ee38d2
3
+ metadata.gz: 2c2ca57f4f352c01930317a9d4a92576b47daaaabb2934ce8bbd5d8f56fd2b76
4
+ data.tar.gz: 7bed7c27f07b94d7a79ed766ecc293ce907e5a531557c67abc9df03a3c33eeee
5
5
  SHA512:
6
- metadata.gz: 5a6f210a2477938bd01610b140a86f4c5034cadc0a37b0d0a916cc3e6d4ddb672a8d61be0e3c78dedc8e372727540de139392c81e0534bc309a57a3792cc1e1c
7
- data.tar.gz: 4f117c5a0f30645f928668390bbd2da2c0ebb9ab2f2b85808288ae173cac9dc282342d45210ffe6e801862632c7432cfa73fcdd9ec143535d5551fcde28653e3
6
+ metadata.gz: df3b3bbae54cc65b204b1c79ad317e8466011d02a1a56aa20704a858b9e06aeda96a63251c1b6df9dce15b71c8fca5d3feb9ec95db0d2110d86482f8b4eaac2c
7
+ data.tar.gz: 74c5d196130b907f3073933037975ef9a00d946177e427f403a9fb2e040ff4e45192e8f75b7708422f63525dbe8ec1fd6503162f058223cfae4f72d4e0cdf4a8
data/README.md CHANGED
@@ -16,6 +16,27 @@ gem install etunnel
16
16
 
17
17
  Requires Ruby >= 2.7 (pulls in faye-websocket).
18
18
 
19
+ ## AI agent quick-start (copy this prompt)
20
+
21
+ ````text
22
+ Integrate etunnel (Ruby SDK) into this project to expose the local service on port <PORT> at a public HTTPS URL.
23
+
24
+ - Package: `etunnel` on RubyGems (needs Ruby >= 2.7) · Install: `gem install etunnel` (pulls faye-websocket + eventmachine)
25
+ - Server: wss://t.etun.uk/tunnel (override with ETUNNEL_SERVER). Anonymous tier = random subdomain, 4h TTL; custom subdomain / longer TTL need a paid token (opts.token or ETUNNEL_TOKEN).
26
+ - Minimal embed (verified against the SDK source):
27
+ ```ruby
28
+ require 'etunnel'
29
+ $stdout.sync = true
30
+ t = Etunnel.connect('wss://t.etun.uk/tunnel', 3000)
31
+ puts "TUNNEL_URL: #{t.url}"
32
+ trap('INT') { t.close; exit }
33
+ sleep
34
+ ```
35
+ - Rules: print the public URL as `TUNNEL_URL: <url>` and keep the process alive; call `t.close` on shutdown to release the subdomain. This SDK is buffer-based (no WebSocket upgrades, no streaming) - fine for webhooks/APIs/dashboards.
36
+ - Do not invent other options. Full API/options: #embed and #multi-target-routing. Wire protocol: https://github.com/topcheer/etunnel/blob/main/PROTOCOL.md
37
+ - Known issue in 1.7.35: `t.resume_token` and the `etunnel` CLI crash (SystemStackError); do not rely on them.
38
+ ````
39
+
19
40
  ## CLI
20
41
 
21
42
  ```
@@ -33,14 +54,31 @@ jitter, reset on success) and prints `TUNNEL_URL:` again. The subdomain is
33
54
  server needs a stable `SESSION_SECRET`; see PROTOCOL.md §1). Set
34
55
  `ETUNNEL_RECONNECT=0` to restore the old one-shot behaviour.
35
56
 
57
+ > **Status 1.7.35:** the gem's `etunnel` executable crashes right after
58
+ > `welcome` (`SystemStackError` in `Etunnel.connect` -> `resume_token`,
59
+ > `lib/etunnel.rb:166`). Use the embed below until a fixed gem is published.
60
+
36
61
  ## Embed
37
62
 
38
63
  ```ruby
39
64
  require 'etunnel'
65
+
66
+ $stdout.sync = true # show the URL immediately even when stdout is a pipe or log
40
67
  t = Etunnel.connect('wss://t.etun.uk/tunnel', 3000)
41
- puts t.url
68
+ puts "TUNNEL_URL: #{t.url}"
69
+
70
+ trap('INT') { t.close; exit } # sends `bye`, frees the subdomain
71
+ sleep # keep the process alive
42
72
  ```
43
73
 
74
+ `Etunnel.connect(server, local, token: nil, subdomain: nil, resume: nil, routes: nil)`
75
+ blocks until `welcome` and returns a tunnel object: `t.url` (public URL),
76
+ `t.resume_token` (server-signed token; replay it via `resume:` to reclaim the
77
+ same subdomain - raises in 1.7.35, see above), `t.close` (sends `bye`).
78
+ `local` is a port, `"host:port"`, or `nil` when `routes` is given. Each
79
+ request is served on a worker thread; EventMachine runs in a background
80
+ thread if no reactor is running (Rails: call `connect` from an initializer).
81
+
44
82
  ## Environment variables
45
83
 
46
84
  | Variable | Meaning | Default |
data/lib/etunnel.rb CHANGED
@@ -71,6 +71,32 @@ module Etunnel
71
71
  nil
72
72
  end
73
73
 
74
+ # Handle returned by Etunnel.connect (#417-E27): url / resume_token
75
+ # readers plus close (sends bye, then closes the socket).
76
+ class Tunnel
77
+ attr_reader :url, :resume_token
78
+
79
+ def initialize(url, resume_token, socket)
80
+ @url = url
81
+ @resume_token = resume_token
82
+ @socket = socket
83
+ end
84
+
85
+ def close
86
+ begin
87
+ @socket.send(JSON.generate({ type: 'bye', reason: 'client closed' }))
88
+ rescue StandardError
89
+ nil # socket already gone - still close below
90
+ end
91
+ begin
92
+ @socket.close
93
+ rescue StandardError
94
+ nil
95
+ end
96
+ nil
97
+ end
98
+ end
99
+
74
100
  def self.connect(server, local, token: nil, subdomain: nil, resume: nil, routes: nil)
75
101
  routes = normalize_routes(routes) if routes
76
102
  raise ArgumentError, 'etunnel: routes must not be empty' if routes && routes.empty?
@@ -99,6 +125,7 @@ module Etunnel
99
125
  ws.send(JSON.generate(hello))
100
126
 
101
127
  url = nil
128
+ resume_token = '' # #417-E27: was only set inside the resumeToken branch - uninitialized otherwise
102
129
  loop do
103
130
  kind, payload = queue.pop
104
131
  raise 'etunnel: connection closed' if kind == :close
@@ -161,14 +188,15 @@ module Etunnel
161
188
  end
162
189
  end
163
190
 
164
- tunnel = Object.new
165
- tunnel.define_singleton_method(:url) { url }
166
- tunnel.define_singleton_method(:resume_token) { resume_token }
167
- tunnel.define_singleton_method(:close) do
168
- ws.send(JSON.generate({ type: 'bye', reason: 'client closed' }))
169
- ws.close
170
- end
171
- tunnel
191
+ # #417-E27 (P0, Ruby 4.0): the tunnel used to be an Object.new with three
192
+ # define_singleton_method blocks closing over locals. On Ruby 4.0 a
193
+ # block handed to define_singleton_method runs with the receiver as
194
+ # self and bare locals inside it (url, ws) resolve as method calls on
195
+ # that receiver - so `url` re-entered the getter we were defining:
196
+ # `stack level too deep` at the first tunnel.url read, same hazard for
197
+ # close's `ws`. Replaced with a plain class whose constructor captures
198
+ # the values: deterministic closure semantics on every Ruby version.
199
+ Tunnel.new(url, resume_token, ws)
172
200
  end
173
201
 
174
202
  # Themed 502 page shown when the local app is down (same HTML as the other SDKs).
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etunnel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.35
4
+ version: 1.7.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - etunnel authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-23 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket