stun 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -14
- data/README.md +4 -3
- data/lib/stun/client.rb +15 -15
- data/lib/stun/version.rb +1 -1
- data/stun.gemspec +3 -3
- metadata +23 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b060d28741f56171298558ebaccca095b5e2022b079ceb0d0debc6da5c64571
|
4
|
+
data.tar.gz: 0315c04d1cbffdbd27dba2753e20c699867db61a48e63f8738edd472c2392cae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e945bcd363a021cbb41e24db39da772ece139b25bc2fef0168b5056aa80feede3f4d8cbc6d79b6bac8dba8e2958e2dad2d933e92258888eeee7012be4ef2a0fd
|
7
|
+
data.tar.gz: 6f6bd4a87ba23b526c35f2101111c49f596b07461fe3ddb0046d79d4410d21b956b8e706fddccc794609c29608b847d9e9ba69d95cdced6e26815865eed0ff25
|
data/Gemfile.lock
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stun
|
5
|
-
bindata (~> 2.4.
|
4
|
+
stun (0.2.1)
|
5
|
+
bindata (~> 2.4.10)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
bindata (2.4.
|
11
|
-
diff-lcs (1.
|
12
|
-
rake (
|
10
|
+
bindata (2.4.10)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
rake (12.3.3)
|
13
13
|
rspec (3.9.0)
|
14
14
|
rspec-core (~> 3.9.0)
|
15
15
|
rspec-expectations (~> 3.9.0)
|
16
16
|
rspec-mocks (~> 3.9.0)
|
17
|
-
rspec-core (3.9.
|
18
|
-
rspec-support (~> 3.9.
|
19
|
-
rspec-expectations (3.9.
|
17
|
+
rspec-core (3.9.3)
|
18
|
+
rspec-support (~> 3.9.3)
|
19
|
+
rspec-expectations (3.9.4)
|
20
20
|
diff-lcs (>= 1.2.0, < 2.0)
|
21
21
|
rspec-support (~> 3.9.0)
|
22
22
|
rspec-mocks (3.9.1)
|
23
23
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
24
|
rspec-support (~> 3.9.0)
|
25
|
-
rspec-support (3.9.
|
25
|
+
rspec-support (3.9.4)
|
26
26
|
|
27
27
|
PLATFORMS
|
28
|
-
|
28
|
+
x86_64-linux
|
29
29
|
|
30
30
|
DEPENDENCIES
|
31
|
-
bundler (~>
|
32
|
-
rake (~>
|
31
|
+
bundler (~> 2.2.33)
|
32
|
+
rake (~> 12.3.3)
|
33
33
|
rspec (~> 3.9.0)
|
34
|
-
stun
|
34
|
+
stun!
|
35
35
|
|
36
36
|
BUNDLED WITH
|
37
|
-
2.
|
37
|
+
2.2.33
|
data/README.md
CHANGED
@@ -18,13 +18,14 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
21
|
```ruby
|
24
22
|
require 'stun'
|
25
23
|
|
24
|
+
socket = UDPSocket.new
|
26
25
|
client = Stun::Client.new(host: '108.177.14.127', port: 19302)
|
27
|
-
client.
|
26
|
+
response = client.query(socket: socket)
|
27
|
+
response.ip # external ip
|
28
|
+
response.port # external port
|
28
29
|
```
|
29
30
|
|
30
31
|
|
data/lib/stun/client.rb
CHANGED
@@ -47,8 +47,7 @@ module Stun
|
|
47
47
|
|
48
48
|
uint16 :value_type
|
49
49
|
uint16 :value_length
|
50
|
-
|
51
|
-
choice :attribute_value, selection: lambda { value_type }, choices: {
|
50
|
+
choice :attribute_value, selection: -> { value_type }, choices: {
|
52
51
|
0x0001 => :mapped_address,
|
53
52
|
0x0002 => :response_address,
|
54
53
|
}
|
@@ -72,32 +71,33 @@ module Stun
|
|
72
71
|
|
73
72
|
uint16 :message_type
|
74
73
|
uint16 :message_length, initial_value: 0
|
75
|
-
string :transaction_id, length: 16, initial_value:
|
76
|
-
buffer :attributes, type: :stun_message_attribute, length:
|
74
|
+
string :transaction_id, length: 16, initial_value: -> { SecureRandom.alphanumeric(16) }
|
75
|
+
buffer :attributes, type: :stun_message_attribute, length: -> { message_length }, onlyif: -> { message_length > 0 }
|
77
76
|
|
78
77
|
def message_type_name
|
79
78
|
MESSAGE_TYPES.fetch(message_type)
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
83
|
-
def initialize(
|
84
|
-
@host =
|
85
|
-
@port =
|
82
|
+
def initialize(host:, port:)
|
83
|
+
@host = host
|
84
|
+
@port = port
|
86
85
|
end
|
87
86
|
|
88
|
-
def
|
87
|
+
def query(socket:)
|
89
88
|
payload = StunMessage.new(message_type: 0x0001).to_binary_s
|
90
|
-
socket
|
91
|
-
socket.connect(@host, @port)
|
92
|
-
socket.send(payload, 0, @host, @port)
|
89
|
+
socket.send(payload, 0, host, port)
|
93
90
|
resp = socket.recv(1024)
|
94
91
|
|
95
92
|
msg = StunMessage.read(resp)
|
96
93
|
attr = msg[:attributes][:attribute_value]
|
97
|
-
|
98
|
-
id: "#{attr[:ip_a]}.#{attr[:ip_b]}.#{attr[:ip_c]}.#{attr[:ip_d]}",
|
99
|
-
port: attr[:port]
|
100
|
-
}
|
94
|
+
QueryResponse.new(ip: attr.ip, port: attr[:port])
|
101
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
QueryResponse = Struct.new(:ip, :port, keyword_init: true)
|
100
|
+
|
101
|
+
attr_reader :host, :port
|
102
102
|
end
|
103
103
|
end
|
data/lib/stun/version.rb
CHANGED
data/stun.gemspec
CHANGED
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_runtime_dependency "bindata", "~> 2.4.
|
26
|
+
spec.add_runtime_dependency "bindata", "~> 2.4.10"
|
27
27
|
|
28
|
-
spec.add_development_dependency "bundler", "~>
|
29
|
-
spec.add_development_dependency "rake", "~>
|
28
|
+
spec.add_development_dependency "bundler", "~> 2.2.33"
|
29
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.9.0"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Kluge
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.4.
|
19
|
+
version: 2.4.10
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.4.
|
26
|
+
version: 2.4.10
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.2.33
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.2.33
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 12.3.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 3.9.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.9.0
|
69
69
|
description: Stun client
|
@@ -73,7 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
77
77
|
- Gemfile
|
78
78
|
- Gemfile.lock
|
79
79
|
- LICENSE.txt
|
@@ -89,23 +89,23 @@ homepage: http://github.com
|
|
89
89
|
licenses:
|
90
90
|
- MIT
|
91
91
|
metadata: {}
|
92
|
-
post_install_message:
|
92
|
+
post_install_message:
|
93
93
|
rdoc_options: []
|
94
94
|
require_paths:
|
95
95
|
- lib
|
96
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
97
97
|
requirements:
|
98
|
-
- -
|
98
|
+
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
|
-
- -
|
103
|
+
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
108
|
-
signing_key:
|
107
|
+
rubygems_version: 3.1.2
|
108
|
+
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Stun client
|
111
111
|
test_files: []
|