tox 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +5 -0
- data/.gitmodules +2 -2
- data/.rubocop.yml +6 -0
- data/.travis.yml +4 -9
- data/README.md +9 -0
- data/Rakefile +112 -3
- data/bin/childprocess +44 -0
- data/examples/echo_bot.rb +11 -7
- data/ext/tox/client.c +579 -285
- data/ext/tox/extconf.rb +187 -133
- data/ext/tox/friend.c +95 -105
- data/ext/tox/options.c +358 -39
- data/ext/tox/tox.c +41 -37
- data/ext/tox/tox.h +201 -21
- data/ext/tox/version.c +0 -18
- data/lib/tox.rb +11 -28
- data/lib/tox/address.rb +12 -16
- data/lib/tox/address_checksum.rb +12 -0
- data/lib/tox/binary.rb +26 -29
- data/lib/tox/client.rb +7 -64
- data/lib/tox/connection_status.rb +23 -0
- data/lib/tox/friend.rb +9 -20
- data/lib/tox/node.rb +1 -17
- data/lib/tox/nospam.rb +9 -16
- data/lib/tox/options.rb +54 -16
- data/lib/tox/out_friend_message.rb +40 -0
- data/lib/tox/out_message.rb +6 -16
- data/lib/tox/proxies/base.rb +54 -0
- data/lib/tox/proxies/http.rb +14 -0
- data/lib/tox/proxies/socks5.rb +14 -0
- data/lib/tox/proxy_type.rb +17 -0
- data/lib/tox/public_key.rb +0 -16
- data/lib/tox/status.rb +0 -16
- data/lib/tox/user_status.rb +0 -16
- data/lib/tox/version.rb +1 -17
- data/tox.gemspec +9 -2
- metadata +29 -7
- data/bin/build/libsodium +0 -11
- data/bin/build/libtoxcore +0 -11
- data/lib/tox/friend/out_message.rb +0 -58
data/lib/tox/address.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# tox.rb - Ruby interface for libtoxcore
|
4
|
-
# Copyright (C) 2015-2017 Braiden Vasco
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
3
|
module Tox
|
20
4
|
##
|
21
5
|
# Address primitive.
|
@@ -24,5 +8,17 @@ module Tox
|
|
24
8
|
def self.bytesize
|
25
9
|
38
|
26
10
|
end
|
11
|
+
|
12
|
+
def public_key
|
13
|
+
@public_key ||= PublicKey.new value[0...32]
|
14
|
+
end
|
15
|
+
|
16
|
+
def nospam
|
17
|
+
@nospam ||= Nospam.new value[32...36]
|
18
|
+
end
|
19
|
+
|
20
|
+
def checksum
|
21
|
+
@checksum ||= AddressChecksum.new value[36...38]
|
22
|
+
end
|
27
23
|
end
|
28
24
|
end
|
data/lib/tox/binary.rb
CHANGED
@@ -1,26 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# tox.rb - Ruby interface for libtoxcore
|
4
|
-
# Copyright (C) 2015-2017 Braiden Vasco
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
3
|
module Tox
|
20
4
|
##
|
21
5
|
# Binary primitive representation.
|
22
6
|
#
|
23
|
-
class Binary
|
7
|
+
class Binary
|
24
8
|
def self.bytesize
|
25
9
|
raise NotImplementedError, "#{self}.bytesize"
|
26
10
|
end
|
@@ -29,30 +13,43 @@ module Tox
|
|
29
13
|
/\A[\da-fA-F]{#{2 * bytesize}}\z/
|
30
14
|
end
|
31
15
|
|
32
|
-
|
16
|
+
attr_reader :value
|
17
|
+
|
18
|
+
def initialize(value)
|
33
19
|
unless value.is_a? String
|
34
20
|
raise TypeError, "expected value to be a #{String}"
|
35
21
|
end
|
36
22
|
|
37
23
|
if value.bytesize == self.class.bytesize
|
38
|
-
|
24
|
+
self.value = value
|
25
|
+
elsif value =~ self.class.hex_re
|
26
|
+
self.hex_value = value
|
39
27
|
else
|
40
|
-
|
41
|
-
raise ArgumentError, 'expected value to be a hex string'
|
42
|
-
end
|
43
|
-
super [value].pack('H*')
|
28
|
+
raise ArgumentError, 'expected value to be a hex or binary string'
|
44
29
|
end
|
45
|
-
|
46
|
-
to_hex
|
47
|
-
freeze
|
48
30
|
end
|
49
31
|
|
50
|
-
def
|
51
|
-
@
|
32
|
+
def to_s
|
33
|
+
@to_s ||= value.unpack('H*').first.upcase.freeze
|
52
34
|
end
|
53
35
|
|
54
36
|
def inspect
|
55
|
-
"#<#{self.class}: \"#{
|
37
|
+
"#<#{self.class}: \"#{self}\">"
|
38
|
+
end
|
39
|
+
|
40
|
+
def ==(other)
|
41
|
+
return false unless self.class == other.class
|
42
|
+
value == other.value
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def value=(value)
|
48
|
+
@value = value.frozen? ? value : value.dup.freeze
|
49
|
+
end
|
50
|
+
|
51
|
+
def hex_value=(value)
|
52
|
+
@value = [value].pack('H*').freeze
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
data/lib/tox/client.rb
CHANGED
@@ -1,57 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# tox.rb - Ruby interface for libtoxcore
|
4
|
-
# Copyright (C) 2015-2017 Braiden Vasco
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
3
|
module Tox
|
20
4
|
##
|
21
5
|
# Tox client.
|
22
6
|
#
|
23
7
|
class Client
|
24
8
|
def initialize(options = Tox::Options.new)
|
9
|
+
@on_friend_request = nil
|
10
|
+
@on_friend_message = nil
|
11
|
+
@on_friend_name_change = nil
|
12
|
+
@on_friend_status_message_change = nil
|
13
|
+
@on_friend_status_change = nil
|
14
|
+
|
25
15
|
initialize_with options
|
26
|
-
self.running = false
|
27
16
|
end
|
28
17
|
|
29
18
|
def bootstrap_official
|
30
19
|
Status.new.udp_nodes.each do |node|
|
31
|
-
bootstrap node
|
20
|
+
bootstrap node.resolv_ipv4, node.port, node.public_key
|
32
21
|
end
|
33
22
|
end
|
34
23
|
|
35
|
-
def running?
|
36
|
-
@running
|
37
|
-
end
|
38
|
-
|
39
|
-
def stop
|
40
|
-
return false unless running?
|
41
|
-
self.running = false
|
42
|
-
true
|
43
|
-
end
|
44
|
-
|
45
|
-
def run
|
46
|
-
unless mutex.try_lock
|
47
|
-
raise AlreadyRunningError, "already running in #{thread}"
|
48
|
-
end
|
49
|
-
|
50
|
-
run_internal
|
51
|
-
|
52
|
-
mutex.unlock
|
53
|
-
end
|
54
|
-
|
55
24
|
def friends
|
56
25
|
friend_numbers.map do |friend_number|
|
57
26
|
friend friend_number
|
@@ -66,10 +35,6 @@ module Tox
|
|
66
35
|
Friend.new(self, number).exist!
|
67
36
|
end
|
68
37
|
|
69
|
-
def on_iteration(&block)
|
70
|
-
@on_iteration = block
|
71
|
-
end
|
72
|
-
|
73
38
|
def on_friend_request(&block)
|
74
39
|
@on_friend_request = block
|
75
40
|
end
|
@@ -90,29 +55,7 @@ module Tox
|
|
90
55
|
@on_friend_status_change = block
|
91
56
|
end
|
92
57
|
|
93
|
-
private
|
94
|
-
|
95
|
-
attr_accessor :thread
|
96
|
-
|
97
|
-
def mutex
|
98
|
-
@mutex ||= Mutex.new
|
99
|
-
end
|
100
|
-
|
101
|
-
def running=(value)
|
102
|
-
@running = !!value
|
103
|
-
end
|
104
|
-
|
105
|
-
def run_internal
|
106
|
-
self.running = true
|
107
|
-
self.thread = Thread.current
|
108
|
-
run_loop
|
109
|
-
ensure
|
110
|
-
self.running = false
|
111
|
-
self.thread = nil
|
112
|
-
end
|
113
|
-
|
114
58
|
class Error < RuntimeError; end
|
115
59
|
class BadSavedataError < Error; end
|
116
|
-
class AlreadyRunningError < Error; end
|
117
60
|
end
|
118
61
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tox
|
4
|
+
##
|
5
|
+
# Protocols that can be used to connect to the network or friends.
|
6
|
+
#
|
7
|
+
module ConnectionStatus
|
8
|
+
# There is no connection. This instance, or the friend the state change
|
9
|
+
# is about, is now offline.
|
10
|
+
NONE = :none
|
11
|
+
|
12
|
+
# A TCP connection has been established. For the own instance, this means
|
13
|
+
# it is connected through a TCP relay, only. For a friend, this means that
|
14
|
+
# the connection to that particular friend goes through a TCP relay.
|
15
|
+
TCP = :tcp
|
16
|
+
|
17
|
+
# A UDP connection has been established. For the own instance, this means
|
18
|
+
# it is able to send UDP packets to DHT nodes, but may still be connected
|
19
|
+
# to a TCP relay. For a friend, this means that the connection
|
20
|
+
# to that particular friend was built using direct UDP packets.
|
21
|
+
UDP = :udp
|
22
|
+
end
|
23
|
+
end
|
data/lib/tox/friend.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# tox.rb - Ruby interface for libtoxcore
|
4
|
-
# Copyright (C) 2015-2017 Braiden Vasco
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
3
|
module Tox
|
20
4
|
##
|
21
5
|
# Friend representation in Tox client.
|
@@ -35,22 +19,27 @@ module Tox
|
|
35
19
|
|
36
20
|
alias exists! exist!
|
37
21
|
|
22
|
+
def ==(other)
|
23
|
+
return false unless self.class == other.class
|
24
|
+
client == other.client &&
|
25
|
+
number == other.number
|
26
|
+
end
|
27
|
+
|
38
28
|
private
|
39
29
|
|
40
30
|
def client=(value)
|
41
31
|
unless value.is_a? Client
|
42
|
-
raise TypeError, "
|
32
|
+
raise TypeError, "Expected #{Client}, got #{value.class}"
|
43
33
|
end
|
44
34
|
@client = value
|
45
35
|
end
|
46
36
|
|
47
37
|
def number=(value)
|
48
38
|
unless value.is_a? Integer
|
49
|
-
raise TypeError, "
|
39
|
+
raise TypeError, "Expected #{Integer}, got #{value.class}"
|
50
40
|
end
|
51
41
|
unless value >= 0
|
52
|
-
raise
|
53
|
-
'expected number to be greater than or equal to zero'
|
42
|
+
raise 'Expected friend number to be greater than or equal to zero'
|
54
43
|
end
|
55
44
|
@number = value
|
56
45
|
end
|
data/lib/tox/node.rb
CHANGED
@@ -1,28 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# tox.rb - Ruby interface for libtoxcore
|
4
|
-
# Copyright (C) 2015-2017 Braiden Vasco
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
3
|
module Tox
|
20
4
|
##
|
21
5
|
# Tox node credentials.
|
22
6
|
#
|
23
7
|
class Node
|
24
8
|
# Range of valid port numbers.
|
25
|
-
PORT_RANGE =
|
9
|
+
PORT_RANGE = 1..65_535
|
26
10
|
|
27
11
|
def initialize(data)
|
28
12
|
@data = data.map { |k, v| [k.to_sym, v] }.to_h.freeze
|
data/lib/tox/nospam.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# tox.rb - Ruby interface for libtoxcore
|
4
|
-
# Copyright (C) 2015-2017 Braiden Vasco
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
3
|
module Tox
|
20
4
|
##
|
21
5
|
# Nospam primitive.
|
@@ -24,5 +8,14 @@ module Tox
|
|
24
8
|
def self.bytesize
|
25
9
|
4
|
26
10
|
end
|
11
|
+
|
12
|
+
def initialize(value)
|
13
|
+
return @value = [value].pack('L').reverse.freeze if value.is_a? Integer
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_i
|
18
|
+
@to_i ||= value.reverse.unpack('L').first
|
19
|
+
end
|
27
20
|
end
|
28
21
|
end
|
data/lib/tox/options.rb
CHANGED
@@ -1,25 +1,63 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# tox.rb - Ruby interface for libtoxcore
|
4
|
-
# Copyright (C) 2015-2017 Braiden Vasco
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
3
|
module Tox
|
20
4
|
##
|
21
5
|
# Startup options for Tox client.
|
22
6
|
#
|
23
7
|
class Options
|
8
|
+
BIND_PORT_RANGE = 0..65_535
|
9
|
+
|
10
|
+
attr_reader :proxy
|
11
|
+
|
12
|
+
def proxy=(value)
|
13
|
+
if value.nil?
|
14
|
+
@proxy = nil
|
15
|
+
set_proxy_params ProxyType::NONE, nil, 0
|
16
|
+
return
|
17
|
+
end
|
18
|
+
unless value.is_a? Proxies::Base
|
19
|
+
raise TypeError, "Expected #{Proxies::Base}, got #{value.class}"
|
20
|
+
end
|
21
|
+
@proxy = value
|
22
|
+
set_proxy_params value.type, value.host, value.port
|
23
|
+
end
|
24
|
+
|
25
|
+
def start_port=(value)
|
26
|
+
unless value.is_a? Integer
|
27
|
+
raise TypeError, "Expected #{Integer}, got #{value.class}"
|
28
|
+
end
|
29
|
+
unless BIND_PORT_RANGE.include? value
|
30
|
+
raise "Expected value to be from range #{BIND_PORT_RANGE}"
|
31
|
+
end
|
32
|
+
self.start_port_internal = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def end_port=(value)
|
36
|
+
unless value.is_a? Integer
|
37
|
+
raise TypeError, "Expected #{Integer}, got #{value.class}"
|
38
|
+
end
|
39
|
+
unless BIND_PORT_RANGE.include? value
|
40
|
+
raise "Expected value to be from range #{BIND_PORT_RANGE}"
|
41
|
+
end
|
42
|
+
self.end_port_internal = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def tcp_port=(value)
|
46
|
+
unless value.is_a? Integer
|
47
|
+
raise TypeError, "Expected #{Integer}, got #{value.class}"
|
48
|
+
end
|
49
|
+
unless BIND_PORT_RANGE.include? value
|
50
|
+
raise "Expected value to be from range #{BIND_PORT_RANGE}"
|
51
|
+
end
|
52
|
+
self.tcp_port_internal = value
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def set_proxy_params(type, host, port)
|
58
|
+
self.proxy_type = type
|
59
|
+
self.proxy_host = host
|
60
|
+
self.proxy_port = port
|
61
|
+
end
|
24
62
|
end
|
25
63
|
end
|