netpump 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG +9 -0
- data/bin/netpump +9 -19
- data/lib/eventmachine/websocket/client.rb +8 -4
- data/lib/eventmachine/websocket/server.rb +1 -1
- data/lib/netpump/client.rb +13 -6
- data/lib/netpump/relay.rb +6 -5
- data/lib/netpump/server.rb +2 -2
- data/public/netpump.html +2 -2
- metadata +16 -4
- data/VERSION +0 -1
- data/public/favicon.png +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6931a624fa28d354c72f47c02c06fe7041784c0a7f31668e66099d3fd3ee37e8
|
|
4
|
+
data.tar.gz: f9a71688a43c7fee6ba692cabd7f3b7903ebdd40388c762f0b643c6e80f0767e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25589fad75f1b12458b5b83273ffae665ab1cf4a31badeb1714d611f20e29de4a97567f06fe9472538021e95ca9bfd7dfbdf20665781c3a08fd3e60091dd54a5
|
|
7
|
+
data.tar.gz: ef0cfa5f786bc386f589d0fd9612a5165ae4051827a6b9b0e3e5561baee74da3cc9247eccfafed53610532436ea02795013c457e320da701aa295ffaed28f841
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
1.0.2
|
|
2
|
+
|
|
3
|
+
Simplify argv parsing code
|
|
4
|
+
Downcase websocket handshake headers
|
|
5
|
+
Add test case for invalid server requests
|
|
6
|
+
Update public np server address
|
|
7
|
+
Allow any base path in remote server URL
|
|
8
|
+
Stop on SIGTERM
|
|
9
|
+
|
|
1
10
|
1.0.1
|
|
2
11
|
|
|
3
12
|
Simplify sequential and parallel request tests
|
data/bin/netpump
CHANGED
|
@@ -12,8 +12,8 @@ copts = {}
|
|
|
12
12
|
sopts = {}
|
|
13
13
|
|
|
14
14
|
op = OptionParser.new do |op|
|
|
15
|
+
op.version = "1.0.2"
|
|
15
16
|
op.summary_width = 24
|
|
16
|
-
|
|
17
17
|
op.banner = "Usage: netpump [options]"
|
|
18
18
|
op.separator ""
|
|
19
19
|
op.separator "Options:"
|
|
@@ -34,15 +34,15 @@ op = OptionParser.new do |op|
|
|
|
34
34
|
raise OptionParser::InvalidArgument, val
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
op.on("-c", "--client MODE", ["direct", "browser"], "start
|
|
37
|
+
op.on("-c", "--client MODE", ["direct", "browser"], "start np client (mode: direct, browser)") do |mode|
|
|
38
38
|
copts[:mode] = mode
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
op.on("--client-host HOST", String, "client host (default: 0.0.0.0)") do |host|
|
|
41
|
+
op.on("--client-host HOST", String, "np client host (default: 0.0.0.0)") do |host|
|
|
42
42
|
copts[:host] = host
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
op.on("--client-port PORT", Port, "client port (default: 8080)") do |port|
|
|
45
|
+
op.on("--client-port PORT", Port, "np client port (default: 8080)") do |port|
|
|
46
46
|
copts[:port] = port
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -54,32 +54,21 @@ op = OptionParser.new do |op|
|
|
|
54
54
|
copts[:proxy_port] = port
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
op.on("--server-url URL", WSS, "
|
|
57
|
+
op.on("--server-url URL", WSS, "remote np server url (default: wss://s.netpump.org)") do |url|
|
|
58
58
|
copts[:server_url] = url
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
op.on("-s", "--server", "start
|
|
61
|
+
op.on("-s", "--server", "start np server") do
|
|
62
62
|
sopts[:server] = true
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
op.on("--server-host HOST", String, "server host (default: 0.0.0.0)") do |host|
|
|
65
|
+
op.on("--server-host HOST", String, "np server host (default: 0.0.0.0)") do |host|
|
|
66
66
|
sopts[:host] = host
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
op.on("--server-port PORT", Port, "server port (default: 10000)") do |port|
|
|
69
|
+
op.on("--server-port PORT", Port, "np server port (default: 10000)") do |port|
|
|
70
70
|
sopts[:port] = port
|
|
71
71
|
end
|
|
72
|
-
|
|
73
|
-
op.on_tail("--version", "print version") do
|
|
74
|
-
version = File.expand_path("../VERSION", __dir__)
|
|
75
|
-
puts(File.read(version))
|
|
76
|
-
exit
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
op.on_tail("--help", "print this help") do
|
|
80
|
-
puts(op)
|
|
81
|
-
exit
|
|
82
|
-
end
|
|
83
72
|
end
|
|
84
73
|
|
|
85
74
|
begin
|
|
@@ -98,6 +87,7 @@ EventMachine.error_handler do |e|
|
|
|
98
87
|
end
|
|
99
88
|
EventMachine.run do
|
|
100
89
|
trap(:INT) { puts; EventMachine.stop }
|
|
90
|
+
trap(:TERM) { EventMachine.stop }
|
|
101
91
|
if sopts.delete(:server)
|
|
102
92
|
server = Netpump::Server.new(**sopts)
|
|
103
93
|
server.start
|
|
@@ -17,10 +17,14 @@ module EventMachine::WebSocket
|
|
|
17
17
|
@parser.on_headers_complete = proc do
|
|
18
18
|
headers = @parser.headers
|
|
19
19
|
@parser = nil
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
headers.transform_keys!(&:downcase)
|
|
21
|
+
con = headers["connection"]
|
|
22
|
+
con&.downcase!
|
|
23
|
+
upg = headers["upgrade"]
|
|
24
|
+
upg&.downcase!
|
|
25
|
+
acc = headers["sec-websocket-accept"]
|
|
26
|
+
acc_ = Digest::SHA1.base64digest(@key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
|
|
27
|
+
unless con == "upgrade" && upg == "websocket" && acc == acc_
|
|
24
28
|
raise HandshakeError, "Invalid server handshake"
|
|
25
29
|
end
|
|
26
30
|
debug [:handshake_completed]
|
|
@@ -34,7 +34,7 @@ module EventMachine::WebSocket::Server
|
|
|
34
34
|
|
|
35
35
|
def ws.serve_file(path)
|
|
36
36
|
send_data("HTTP/1.1 200 OK\r\n\r\n")
|
|
37
|
-
#
|
|
37
|
+
# windows: send/stream_file_data do not work
|
|
38
38
|
send_data(path.read)
|
|
39
39
|
close_connection_after_writing
|
|
40
40
|
end
|
data/lib/netpump/client.rb
CHANGED
|
@@ -15,14 +15,19 @@ module Netpump
|
|
|
15
15
|
port: "8080",
|
|
16
16
|
proxy_host: "127.0.0.1",
|
|
17
17
|
proxy_port: 3128,
|
|
18
|
-
server_url: "wss://
|
|
18
|
+
server_url: "wss://s.netpump.org",
|
|
19
19
|
connection_inactivity_timeout: 30.0,
|
|
20
20
|
websocket_pool_size: 20,
|
|
21
21
|
websocket_pool_timeout: 60.0
|
|
22
22
|
)
|
|
23
23
|
@mode = mode
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
if mode == "browser"
|
|
25
|
+
@host = host
|
|
26
|
+
@port = port
|
|
27
|
+
else
|
|
28
|
+
@host = nil
|
|
29
|
+
@port = nil
|
|
30
|
+
end
|
|
26
31
|
@proxy_host = proxy_host
|
|
27
32
|
@proxy_port = proxy_port
|
|
28
33
|
@server_url = URI(server_url)
|
|
@@ -33,10 +38,12 @@ module Netpump
|
|
|
33
38
|
@control_ws = nil
|
|
34
39
|
@log = lambda { |msg, **ctx| log(msg, c: true, **ctx) }
|
|
35
40
|
@ready = EventMachine::Completion.new
|
|
41
|
+
@ready.callback do
|
|
42
|
+
@log.call "[+] np client is ready.", mode: @mode, host: @host, port: @port
|
|
43
|
+
end
|
|
36
44
|
end
|
|
37
45
|
|
|
38
46
|
def start
|
|
39
|
-
@log.call "[+] netpump client is starting.", mode: @mode, host: @host, port: @port
|
|
40
47
|
case @mode
|
|
41
48
|
when "direct"
|
|
42
49
|
start_proxy_server
|
|
@@ -73,7 +80,7 @@ module Netpump
|
|
|
73
80
|
@control_ws = nil
|
|
74
81
|
@log.call "[-] device is disconnected.", sig: ws.signature
|
|
75
82
|
EventMachine.stop_server(proxy)
|
|
76
|
-
@log.call "[-] proxy server is stopped."
|
|
83
|
+
@log.call "[-] np proxy server is stopped."
|
|
77
84
|
end
|
|
78
85
|
@ready.succeed
|
|
79
86
|
end
|
|
@@ -103,7 +110,7 @@ module Netpump
|
|
|
103
110
|
proxy = EventMachine.start_server(@proxy_host, @proxy_port, Relay, "c") do |relay|
|
|
104
111
|
bind(relay)
|
|
105
112
|
end
|
|
106
|
-
@log.call "[+] proxy server is ready.", type: "https", host: @proxy_host, port: @proxy_port
|
|
113
|
+
@log.call "[+] np proxy server is ready.", type: "https", host: @proxy_host, port: @proxy_port
|
|
107
114
|
proxy
|
|
108
115
|
end
|
|
109
116
|
|
data/lib/netpump/relay.rb
CHANGED
|
@@ -34,10 +34,11 @@ module Netpump
|
|
|
34
34
|
@remote_ip = remote_ip
|
|
35
35
|
@connection_inactivity_timeout = comm_inactivity_timeout
|
|
36
36
|
if @closed
|
|
37
|
-
# If a connection is closed due to the pool timeout before being bound
|
|
38
|
-
# a websocket, it is not added to the wait queue in the websocket
|
|
39
|
-
# so this case should not happen under normal operation. However,
|
|
40
|
-
# still possible
|
|
37
|
+
# If a connection is closed due to the pool timeout before being bound
|
|
38
|
+
# to a websocket, it is not added to the wait queue in the websocket
|
|
39
|
+
# pool, so this case should not happen under normal operation. However,
|
|
40
|
+
# it is still possible if the connection is closed due to any other
|
|
41
|
+
# reason.
|
|
41
42
|
@log.call "[!] bound closed before bind."
|
|
42
43
|
@completion.succeed
|
|
43
44
|
return @completion
|
|
@@ -97,7 +98,7 @@ module Netpump
|
|
|
97
98
|
reason = errno.exception.message
|
|
98
99
|
reason[0] = reason[0].downcase
|
|
99
100
|
else
|
|
100
|
-
#
|
|
101
|
+
# windows: errno can be set to :unknown
|
|
101
102
|
reason = errno.to_s
|
|
102
103
|
end
|
|
103
104
|
@log.call "[-] unbind.", reason: reason
|
data/lib/netpump/server.rb
CHANGED
|
@@ -15,7 +15,6 @@ module Netpump
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def start
|
|
18
|
-
@log.call "[+] netpump server is starting.", host: @host, port: @port
|
|
19
18
|
start_websocket_server
|
|
20
19
|
proxy = EventMachine.start_server(
|
|
21
20
|
@proxy_host, @proxy_port, EventMachine::Protocols::CONNECT
|
|
@@ -23,6 +22,7 @@ module Netpump
|
|
|
23
22
|
fail "inactivity timeout" unless c.comm_inactivity_timeout.zero?
|
|
24
23
|
end
|
|
25
24
|
@proxy_port, @proxy_host = Socket.unpack_sockaddr_in(EventMachine.get_sockname(proxy))
|
|
25
|
+
@log.call "[+] np server is ready.", host: @host, port: @port
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
private
|
|
@@ -41,7 +41,7 @@ module Netpump
|
|
|
41
41
|
bind(ws, ip)
|
|
42
42
|
end
|
|
43
43
|
else
|
|
44
|
-
|
|
44
|
+
next false
|
|
45
45
|
end
|
|
46
46
|
true
|
|
47
47
|
end
|
data/public/netpump.html
CHANGED
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
// client websocket.
|
|
64
64
|
var client;
|
|
65
65
|
// Connect to the server first, so that when we
|
|
66
|
-
// connect to the client the whole chain is complete.
|
|
67
|
-
var server = new WebSocket(
|
|
66
|
+
// connect to the client, the whole chain is complete.
|
|
67
|
+
var server = new WebSocket(new URL("/ws/rem/relay", serverAddr));
|
|
68
68
|
// Log server errors.
|
|
69
69
|
server.onerror = function (event) {
|
|
70
70
|
console.error("[!] server/error", event);
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: netpump
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- soylent
|
|
@@ -9,6 +9,20 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: base64
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0.0'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: em-websocket
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -43,7 +57,6 @@ extensions: []
|
|
|
43
57
|
extra_rdoc_files: []
|
|
44
58
|
files:
|
|
45
59
|
- CHANGELOG
|
|
46
|
-
- VERSION
|
|
47
60
|
- bin/netpump
|
|
48
61
|
- lib/eventmachine/websocket/client.rb
|
|
49
62
|
- lib/eventmachine/websocket/server.rb
|
|
@@ -52,7 +65,6 @@ files:
|
|
|
52
65
|
- lib/netpump/log.rb
|
|
53
66
|
- lib/netpump/relay.rb
|
|
54
67
|
- lib/netpump/server.rb
|
|
55
|
-
- public/favicon.png
|
|
56
68
|
- public/favicon.svg
|
|
57
69
|
- public/netpump.html
|
|
58
70
|
homepage: https://netpump.org
|
|
@@ -75,5 +87,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
75
87
|
requirements: []
|
|
76
88
|
rubygems_version: 3.6.9
|
|
77
89
|
specification_version: 4
|
|
78
|
-
summary:
|
|
90
|
+
summary: tiny websocket proxy tunnel
|
|
79
91
|
test_files: []
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.0.1
|
data/public/favicon.png
DELETED
|
Binary file
|