etunnel 1.7.35 → 1.7.37

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 +37 -3
  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: e575dd50595ae77ac4a0de148917a9bb0ee6f8329f2eea6c614c9b85477ec45f
4
+ data.tar.gz: 6728ee2481cd9896ccdd1b112f743c6b016b6f311bd29a78a1989e0ea964f4c2
5
5
  SHA512:
6
- metadata.gz: 5a6f210a2477938bd01610b140a86f4c5034cadc0a37b0d0a916cc3e6d4ddb672a8d61be0e3c78dedc8e372727540de139392c81e0534bc309a57a3792cc1e1c
7
- data.tar.gz: 4f117c5a0f30645f928668390bbd2da2c0ebb9ab2f2b85808288ae173cac9dc282342d45210ffe6e801862632c7432cfa73fcdd9ec143535d5551fcde28653e3
6
+ metadata.gz: 7c794db0554a2d39159eaa6361fec9b319d1bccf3285426e9045668c7e408755e125fb75a207f45211f74e2eb06bada3d355793a5d3c502c2a15549a5fa8caf4
7
+ data.tar.gz: 8581460cde7022adc7192945b54318d6a9027ccfddc87b83f31777733238b6a5a858dc8d5149db525c9708fd2314d1889d59ecb6c10afb971a0424ee970a4d06
data/README.md CHANGED
@@ -16,14 +16,35 @@ 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
+ ````
38
+
19
39
  ## CLI
20
40
 
21
41
  ```
22
42
  etunnel 3000
23
43
  ```
24
44
 
25
- Prints `TUNNEL_URL: https://<subdomain>.t.etun.uk` — that URL now routes to
26
- your local service. Ctrl-C closes the tunnel.
45
+ `bin/etunnel` calls `Etunnel.main`, which reads `ETUNNEL_*`, prints
46
+ `TUNNEL_URL: https://<subdomain>.t.etun.uk` — that URL now routes to
47
+ your local service — and exits 0 on Ctrl-C.
27
48
 
28
49
  **Reconnects automatically.** If the connection drops (including a server
29
50
  restart) the CLI re-dials with exponential backoff (500ms → 30s, ±20%
@@ -37,10 +58,23 @@ server needs a stable `SESSION_SECRET`; see PROTOCOL.md §1). Set
37
58
 
38
59
  ```ruby
39
60
  require 'etunnel'
61
+
62
+ $stdout.sync = true # show the URL immediately even when stdout is a pipe or log
40
63
  t = Etunnel.connect('wss://t.etun.uk/tunnel', 3000)
41
- puts t.url
64
+ puts "TUNNEL_URL: #{t.url}"
65
+
66
+ trap('INT') { t.close; exit } # sends `bye`, frees the subdomain
67
+ sleep # keep the process alive
42
68
  ```
43
69
 
70
+ `Etunnel.connect(server, local, token: nil, subdomain: nil, resume: nil, routes: nil)`
71
+ blocks until `welcome` and returns an `Etunnel::Tunnel`: `t.url` (public URL),
72
+ `t.resume_token` (server-signed token; replay it via `resume:` to reclaim the
73
+ same subdomain), `t.close` (sends `bye`).
74
+ `local` is a port, `"host:port"`, or `nil` when `routes` is given. Each
75
+ request is served on a worker thread; EventMachine runs in a background
76
+ thread if no reactor is running (Rails: call `connect` from an initializer).
77
+
44
78
  ## Environment variables
45
79
 
46
80
  | 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.37
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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket