c3d 0.3.0 → 0.3.5
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/Gemfile.lock +1 -1
- data/Rakefile +0 -7
- data/lib/c3d.rb +19 -39
- data/lib/c3d/connect_ethereum_rpc.rb +147 -0
- data/lib/c3d/connect_ethereum_socket.rb +122 -0
- data/lib/c3d/connect_torrent.rb +2 -20
- data/lib/c3d/connect_ui.rb +71 -21
- data/lib/c3d/processes.rb +44 -0
- data/lib/c3d/publish.rb +27 -28
- data/lib/c3d/setup.rb +105 -0
- data/lib/c3d/subscribe.rb +103 -8
- data/lib/c3d/util.rb +22 -0
- data/lib/c3d/version.rb +1 -1
- data/settings/c3d-config.json +17 -0
- data/settings/transmission.json +67 -0
- metadata +9 -5
- data/ethereum_bridge.js +0 -61
- data/lib/c3d/connect_ethereum.rb +0 -67
- data/lib/system-setup.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 201a408f2b1225395095cf724407ff44421d53fc
|
4
|
+
data.tar.gz: 678e8aebd10af7dfbe8a16335247202f40dcc1c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da221566c106410d2a1d6c7dd1e0902cc096f3fee448354bcc3f79bcd9364b0322e9bb2c71572052e1d4b512d51bfc6c35ee3c63dc9fcdc5ca138bde967b7caa
|
7
|
+
data.tar.gz: 578d967c0d82ee1e8f41fce0b9a71523bb0598ee7b1146316889341df882e122368f903486a8865a012d0baf727a4d4fb083ba1c528e0186bb0f24babbbef206
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
data/lib/c3d.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
require 'digest/sha1'
|
5
5
|
require 'json'
|
6
6
|
require 'yaml'
|
7
|
+
require 'base64'
|
7
8
|
|
8
9
|
# Gem Dependencies
|
9
10
|
require 'httparty'
|
@@ -11,45 +12,24 @@ require 'bencode'
|
|
11
12
|
require 'celluloid/autostart'
|
12
13
|
|
13
14
|
# This Gem
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
UI_ADDRESS = 'tcp://127.0.0.1:31314'
|
31
|
-
WATCH_FILE = File.join(SWARM_DIR, 'watchers.json')
|
32
|
-
IGNORE_FILE = File.join(SWARM_DIR, 'ignored.json')
|
33
|
-
|
34
|
-
# todo - check that torrent manager is running
|
35
|
-
# todo - torrentapis use a 'fairly std' rpc framework, but with different
|
36
|
-
# endpoints. need to test these though
|
37
|
-
# todo - check dependencies are installed: zmq ... transmission
|
38
|
-
# todo - add foreman
|
39
|
-
|
40
|
-
swarm_puller = TorrentAPI.new(
|
41
|
-
username: TORRENT_USER,
|
42
|
-
password: TORRENT_PASS,
|
43
|
-
url: TORRENT_RPC,
|
44
|
-
debug_mode: true
|
45
|
-
)
|
46
|
-
eth = ConnectEth.new
|
15
|
+
Dir[File.dirname(__FILE__) + '/c3d/*.rb'].each {|file| require file }
|
16
|
+
|
17
|
+
SetupC3D.new
|
18
|
+
|
19
|
+
TransmissionRunner.new.start_transmission
|
20
|
+
sleep 5
|
21
|
+
|
22
|
+
TorrentAPI.supervise_as :puller, {
|
23
|
+
username: ENV['TORRENT_USER'],
|
24
|
+
password: ENV['TORRENT_PASS'],
|
25
|
+
url: ENV['TORRENT_RPC'] }
|
26
|
+
@swarm_puller = Celluloid::Actor[:puller]
|
27
|
+
|
28
|
+
@eth = ConnectEthZMQ.new
|
29
|
+
# @ui = ConnectUI.new
|
30
|
+
# @ui.async.run
|
47
31
|
|
48
32
|
if __FILE__==$0
|
49
|
-
|
50
|
-
|
51
|
-
PublishBlob.new blob1, swarm_puller, eth, false, false, false
|
52
|
-
blob2 = 'as;dlfkajfbdposdituy2q-034956712840918734uytgqklerjdnga,.fxsnvbmaz x.,c'
|
53
|
-
PublishBlob.new blob2, swarm_puller, eth, false, false, false
|
54
|
-
end
|
33
|
+
blob1 = File.read(ARGV[0]) + "\n#{Time.now}"
|
34
|
+
Publish.new @swarm_puller, @eth, blob1, 'a6cb63ec28c12929bee2d3567bf98f374a0b7167', '97d1f086800920e8fd2344be52fb22d7bf6036d2', '0x2E737671893D33BF53A5F00EDE9E839F9D86E3A391387CA9189CA79729D00000'
|
55
35
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Transactions:
|
4
|
+
# * `add-blob-to-g`: add blob to group (params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
5
|
+
# * `rm-blob-from-g`: remove blob from contract (params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
6
|
+
|
7
|
+
require 'socket'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
class ConnectEthRPC
|
11
|
+
include Celluloid
|
12
|
+
|
13
|
+
def initialize client, host=ENV['ETH_HOST'], port=ENV['ETH_PORT']
|
14
|
+
@client = client
|
15
|
+
@question_socket = TCPSocket.new host, port
|
16
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] c3D->eth via RPC on port >>\t#{ENV['ETH_PORT']}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_storage_at address, storage_location
|
20
|
+
address = guard_addresses address
|
21
|
+
storage_location = guard_addresses storage_location
|
22
|
+
|
23
|
+
case @client
|
24
|
+
when :go
|
25
|
+
request = {
|
26
|
+
id: 1,
|
27
|
+
method: "EthereumApi.GetStorageAt",
|
28
|
+
params: [{
|
29
|
+
address: address,
|
30
|
+
key: storage_location
|
31
|
+
}]
|
32
|
+
}
|
33
|
+
when :cpp
|
34
|
+
request = {
|
35
|
+
id: 1,
|
36
|
+
method: "storageAt",
|
37
|
+
params: [{
|
38
|
+
a: address,
|
39
|
+
x: storage_location
|
40
|
+
}]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
send_command request
|
45
|
+
end
|
46
|
+
|
47
|
+
def transact recipient, key='', data='', value=0, gas=10000, gas_price=100000
|
48
|
+
recipient = guard_addresses recipient
|
49
|
+
|
50
|
+
case @client
|
51
|
+
when :go
|
52
|
+
request = {
|
53
|
+
id: 1,
|
54
|
+
method: "EthereumApi.Transact",
|
55
|
+
params: [{
|
56
|
+
recipient: recipient,
|
57
|
+
value: value,
|
58
|
+
gas: gas,
|
59
|
+
gasprice: gas_price
|
60
|
+
}]
|
61
|
+
}
|
62
|
+
when :cpp
|
63
|
+
request = {
|
64
|
+
id: 1,
|
65
|
+
method: 'transact',
|
66
|
+
params: [{
|
67
|
+
sec: '',#todo: key,
|
68
|
+
xValue: value,
|
69
|
+
aDest: recipient,
|
70
|
+
bData: '',#todo: build_data data,
|
71
|
+
xGas: gas,
|
72
|
+
xGasPrice: gas_price
|
73
|
+
}]
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
send_command request
|
78
|
+
end
|
79
|
+
|
80
|
+
def create body_file, endowment=0, key='', gas=10000, gas_price=100000
|
81
|
+
body_content = File.read(body_file)
|
82
|
+
|
83
|
+
case @client
|
84
|
+
when :go
|
85
|
+
request = {
|
86
|
+
id: 1,
|
87
|
+
method: "EthereumApi.Create",
|
88
|
+
params: [{
|
89
|
+
init: '',
|
90
|
+
body: body_content,
|
91
|
+
value: endowment,
|
92
|
+
gas: gas,
|
93
|
+
gasprice: gas_price
|
94
|
+
}]
|
95
|
+
}
|
96
|
+
when :cpp
|
97
|
+
request = {
|
98
|
+
id: 1,
|
99
|
+
method: "create",
|
100
|
+
params: [{
|
101
|
+
sec: '',#todo: key,
|
102
|
+
xEndowment: endowment,
|
103
|
+
bCode: body_content,
|
104
|
+
xGas: gas,
|
105
|
+
xGasPrice: gas_price
|
106
|
+
}]
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
send_command request
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def guard_addresses address
|
116
|
+
unless address[0..1] == "0x"
|
117
|
+
address = "0x" + address
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def build_data data
|
122
|
+
if data.class == Array
|
123
|
+
slots = data[0].to_i
|
124
|
+
data.each do |piece|
|
125
|
+
#todo, encode the pieces...
|
126
|
+
end
|
127
|
+
else
|
128
|
+
return data
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def send_command request
|
133
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Sending Question >>\t#{request}"
|
134
|
+
@question_socket.puts request.to_json
|
135
|
+
handle_response JSON.parse(@question_socket.gets)
|
136
|
+
end
|
137
|
+
|
138
|
+
def handle_response response
|
139
|
+
unless response["error"]
|
140
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Received Answer >>\tanswer:#{response['result']}"
|
141
|
+
return JSON.parse(response["result"])
|
142
|
+
else
|
143
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Received Answer >>\tERROR!"
|
144
|
+
return nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Transactions:
|
4
|
+
# * `add-blob-to-g`: add blob to group (params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
5
|
+
# * `rm-blob-from-g`: remove blob from contract (params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
6
|
+
|
7
|
+
require 'json'
|
8
|
+
require 'celluloid/zmq'
|
9
|
+
|
10
|
+
Celluloid::ZMQ.init
|
11
|
+
|
12
|
+
class ConnectEthZMQ
|
13
|
+
include Celluloid::ZMQ
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@question_socket = ReqSocket.new
|
17
|
+
begin
|
18
|
+
@question_socket.connect ENV['ETH_ZMQ_ADDR']
|
19
|
+
rescue IOError
|
20
|
+
@question_socket.close
|
21
|
+
end
|
22
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] c3D->eth via ZMQ and JS Socket on port >>\t#{ENV['ETH_ZMQ_ADDR'].split(':').last}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_storage_at address, storage_location
|
26
|
+
address = guard_addresses address
|
27
|
+
storage_location = guard_addresses storage_location
|
28
|
+
|
29
|
+
request = {
|
30
|
+
method: 'getStorageAt',
|
31
|
+
params: [
|
32
|
+
address,
|
33
|
+
storage_location
|
34
|
+
]
|
35
|
+
}
|
36
|
+
|
37
|
+
send_message request
|
38
|
+
end
|
39
|
+
|
40
|
+
def transact recipient, key='', data='', value=0, gas=10000
|
41
|
+
recipient = guard_addresses recipient
|
42
|
+
#todo -- add variable gas_price
|
43
|
+
|
44
|
+
request = {
|
45
|
+
method: 'transact',
|
46
|
+
params: [
|
47
|
+
key, #todo -- fix this -- especially in the socket listeners.
|
48
|
+
value,
|
49
|
+
recipient,
|
50
|
+
gas,
|
51
|
+
data #todo -- audit this
|
52
|
+
].flatten
|
53
|
+
}
|
54
|
+
|
55
|
+
send_message request
|
56
|
+
end
|
57
|
+
|
58
|
+
def create body_file, endowment=0, key='', gas=10000
|
59
|
+
body = File.read(body_file)
|
60
|
+
#todo -- add variable gas_price
|
61
|
+
|
62
|
+
request = {
|
63
|
+
method: 'create',
|
64
|
+
params: [
|
65
|
+
key, #todo -- fix this -- especially in the socket listeners.
|
66
|
+
endowment,
|
67
|
+
body,
|
68
|
+
gas
|
69
|
+
]
|
70
|
+
}
|
71
|
+
|
72
|
+
send_message request
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def guard_addresses address
|
78
|
+
unless address[0..1] == "0x"
|
79
|
+
address = "0x" + address
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def send_message request
|
84
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Sending Question >>\t#{request}"
|
85
|
+
@question_socket.send request.to_json
|
86
|
+
handle_response JSON.load(@question_socket.read)
|
87
|
+
end
|
88
|
+
|
89
|
+
def handle_response response
|
90
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Received Answer >>\tsuccess:#{response['success']}\tanswer:#{response['answer']}"
|
91
|
+
return response['answer']
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if __FILE__==$0
|
96
|
+
ENV['ETH_ZMQ_ADDR'] = 'tcp://127.0.0.1:31315'
|
97
|
+
|
98
|
+
message = {}
|
99
|
+
message['method'] = 'transact'
|
100
|
+
message['params'] = [
|
101
|
+
'a6cb63ec28c12929bee2d3567bf98f374a0b7167', #senderaddr
|
102
|
+
'', #value
|
103
|
+
'61363f0d19cfe71a5c130642016e37649610294b', #recipientaddr
|
104
|
+
'10000', #gas
|
105
|
+
'3', #dataslots
|
106
|
+
'newp', #....data
|
107
|
+
'0x76A46EAB30845C1FA2C0E08243890CDFBF73D6421CFA5BF9169FFB98A3300000',
|
108
|
+
'0x1d822cb2e4c60c3a8a85546304072b14fb9de94e2c0c608c4120b5d529590c9d'
|
109
|
+
]
|
110
|
+
questions_for_eth = ConnectEth.new
|
111
|
+
questions_for_eth.write JSON.dump message
|
112
|
+
|
113
|
+
message = {}
|
114
|
+
message['method'] = 'getStorageAt'
|
115
|
+
message['params'] = [
|
116
|
+
'61363f0d19cfe71a5c130642016e37649610294b',
|
117
|
+
'0x76A46EAB30845C1FA2C0E08243890CDFBF73D6421CFA5BF9169FFB98A3300003'
|
118
|
+
]
|
119
|
+
|
120
|
+
questions_for_eth.write JSON.dump message
|
121
|
+
sleep
|
122
|
+
end
|
data/lib/c3d/connect_torrent.rb
CHANGED
@@ -59,7 +59,7 @@ class TorrentAPI
|
|
59
59
|
:method => "torrent-add",
|
60
60
|
:arguments => {
|
61
61
|
:filename => filename,
|
62
|
-
:'download-dir' => BLOBS_DIR,
|
62
|
+
:'download-dir' => ENV['BLOBS_DIR'],
|
63
63
|
:'peer-limit' => 99
|
64
64
|
}
|
65
65
|
)
|
@@ -144,22 +144,4 @@ class TorrentAPI
|
|
144
144
|
log headers
|
145
145
|
log "------------------"
|
146
146
|
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# added = swarm_puller.create("#{t.magnet_link}")
|
150
|
-
|
151
|
-
# [{"addedDate"=>1400177739,
|
152
|
-
# "files"=>
|
153
|
-
# [{"bytesCompleted"=>31752192,
|
154
|
-
# "length"=>591396864,
|
155
|
-
# "name"=>"ubuntu-14.04-server-amd64.iso"}],
|
156
|
-
# "id"=>1,
|
157
|
-
# "isFinished"=>false,
|
158
|
-
# "name"=>"ubuntu-14.04-server-amd64.iso",
|
159
|
-
# "percentDone"=>0.0536,
|
160
|
-
# "rateDownload"=>706000,
|
161
|
-
# "rateUpload"=>3000,
|
162
|
-
# "totalSize"=>591396864}]
|
163
|
-
|
164
|
-
# swarm_puller.destroy(1)
|
165
|
-
# torrent = swarm_puller.find(1)
|
147
|
+
end
|
data/lib/c3d/connect_ui.rb
CHANGED
@@ -4,17 +4,40 @@ require 'json'
|
|
4
4
|
require 'celluloid/zmq'
|
5
5
|
|
6
6
|
# commands - sent over ZMQ but using a standard JSONRPC structure.
|
7
|
-
# * `
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# * `
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# * `
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# * `
|
17
|
-
#
|
7
|
+
# * `makeBlob`: make blob
|
8
|
+
# params: filename: "FILENAME" || filecontents: "CONTENTS"
|
9
|
+
# returns success: BLOB_ID or error
|
10
|
+
# * `destroyBlob`: destroy blob
|
11
|
+
# params: blob: "BLOB_ID"
|
12
|
+
# returns success: true or error
|
13
|
+
# * `addBlobToG`: add blob to group
|
14
|
+
# params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID"
|
15
|
+
# returns success: true or error
|
16
|
+
# * `rmBlobFromG`: remove blob from contract
|
17
|
+
# params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID"
|
18
|
+
# returns success: true or error
|
19
|
+
# * `subscribeK`: add a contract's blobs to the subscribed list
|
20
|
+
# params: contract: "CONTRACT_ADDRESS"
|
21
|
+
# returns success: true or error
|
22
|
+
# * `subscribeG`: add a group's blobs to the subscribed list
|
23
|
+
# params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID"
|
24
|
+
# returns success: true or error
|
25
|
+
# * `unsubscribeK` remove a contract's blobs from the subscribed list
|
26
|
+
# params: contract: "CONTRACT_ADDRESS"
|
27
|
+
# returns success: true or error
|
28
|
+
# * `unsubscribeG` remove a group's blobs from the subscribed list
|
29
|
+
# params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID"
|
30
|
+
# returns success: true or error
|
31
|
+
# * `ignoreG` add a group to the ignore list
|
32
|
+
# params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID"
|
33
|
+
# returns success: true or error
|
34
|
+
# * `publish`: sugar for make blob + add to g
|
35
|
+
# params: filename: "FILENAME" || filecontents: "CONTENTS",
|
36
|
+
# contract: "CONTRACT_ADDRESS", [group]: ["GROUP1_ID", "GROUP2_ID", ...]
|
37
|
+
# returns success: BLOB_ID or error)
|
38
|
+
# * `get`: add a magnet link to the cache
|
39
|
+
# params: id: "BLOB_ID"
|
40
|
+
# returns success: true or error
|
18
41
|
|
19
42
|
Celluloid::ZMQ.init
|
20
43
|
|
@@ -25,13 +48,13 @@ class ConnectUI
|
|
25
48
|
@answer_socket = RepSocket.new
|
26
49
|
|
27
50
|
begin
|
28
|
-
@answer_socket.bind UI_ADDRESS
|
51
|
+
@answer_socket.bind ENV['UI_ADDRESS']
|
29
52
|
rescue IOError
|
30
53
|
@answer_socket.close
|
31
54
|
raise
|
32
55
|
end
|
33
56
|
|
34
|
-
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] c3D<-ui on port >>\t#{UI_ADDRESS.split(':').last}"
|
57
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] c3D<-ui on port >>\t#{ENV['UI_ADDRESS'].split(':').last}"
|
35
58
|
end
|
36
59
|
|
37
60
|
def run
|
@@ -41,12 +64,39 @@ class ConnectUI
|
|
41
64
|
|
42
65
|
def handle_message message
|
43
66
|
message = JSON.load message
|
44
|
-
|
67
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Received Question >>\tcommand:#{message['command']}\tparams:#{message['params']}"
|
68
|
+
case message['command']
|
69
|
+
when 'get'
|
70
|
+
# todo
|
71
|
+
when 'makeBlob'
|
72
|
+
blob = message['params'][0]
|
73
|
+
PublishBlob.new blob, nil
|
74
|
+
when 'destroyBlob'
|
75
|
+
#todo
|
76
|
+
when 'addBlobToG'
|
77
|
+
sending_addr = message['params'][0]
|
78
|
+
contract_id = message['params'][1]
|
79
|
+
group_id = message['params'][2]
|
80
|
+
PublishBlob.new nil, sending_addr, contract_id, group_id
|
81
|
+
when 'rmBlobFromG'
|
82
|
+
#todo
|
83
|
+
when 'subscribeK'
|
84
|
+
#todo
|
85
|
+
when 'subscribeG'
|
86
|
+
#todo
|
87
|
+
when 'unsubscribeK'
|
88
|
+
#todo
|
89
|
+
when 'unsubscribeG'
|
90
|
+
#todo
|
91
|
+
when 'ignoreG'
|
92
|
+
#todo
|
93
|
+
when 'publish'
|
94
|
+
sending_addr = message['params'][0]
|
95
|
+
contract_id = message['params'][1]
|
96
|
+
group_id = message['params'][2]
|
97
|
+
blob = message['params'][3]
|
98
|
+
PublishBlob.new blob, sending_addr, contract_id, group_id
|
99
|
+
end
|
100
|
+
@answer_socket.send JSON.dump message
|
45
101
|
end
|
46
|
-
end
|
47
|
-
|
48
|
-
if __FILE__==$0
|
49
|
-
UI_ADDRESS = 'tcp://127.0.0.1:31314'
|
50
|
-
answers_for_eth = ConnectUI.new
|
51
|
-
answers_for_eth.async.run
|
52
|
-
end
|
102
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class TransmissionRunner
|
4
|
+
def start_transmission
|
5
|
+
unless is_trans_running?
|
6
|
+
pid = spawn "transmission-daemon -f --no-incomplete-dir -o -C -p #{ENV['TORRENT_RPC'].split(':').last[0..3]} -w #{ENV['BLOBS_DIR']} -g #{File.join(ENV['HOME'], '.epm')}"
|
7
|
+
at_exit { Process.kill("INT", pid) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_trans_running?
|
12
|
+
a = `ps ux`.split("\n").select{|e| e[/transmission-daemon/]}
|
13
|
+
return (! a.empty?)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class EthZmqRunner
|
18
|
+
def start_ethereum_zmq_bridge
|
19
|
+
unless is_bridge_running?
|
20
|
+
c3d_node = File.join(File.dirname(__FILE__), '..', '..', 'node_modules', 'c3d', 'connect_aleth.js')
|
21
|
+
pid = spawn "node #{c3d_node}"
|
22
|
+
at_exit { Process.kill("INT", pid) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def is_bridge_running?
|
27
|
+
a = `ps ux`.split("\n").select{|e| e[/node.*connect_aleth.js$/]}
|
28
|
+
return (! a.empty?)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class EthRunner
|
33
|
+
def start_ethereum
|
34
|
+
unless is_eth_running?
|
35
|
+
pid = spawn #{todo}""
|
36
|
+
at_exit { Process.kill("INT", pid) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_eth_running?
|
41
|
+
a = `ps ux`.split("\n").select{|e| e[/eth/]} #todo cleanup
|
42
|
+
return (! a.empty?)
|
43
|
+
end
|
44
|
+
end
|
data/lib/c3d/publish.rb
CHANGED
@@ -1,28 +1,33 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# based off of work by @mukaibot here: https://github.com/mukaibot/mktorrent/blob/master/lib/mktorrent.rb
|
3
3
|
# and work by @Burgestrand here: https://gist.github.com/Burgestrand/1733611
|
4
|
-
# note `rhash` dependency
|
5
4
|
|
6
|
-
class
|
5
|
+
class Publish
|
7
6
|
include Celluloid
|
8
7
|
attr_accessor :tor_file, :blob_file, :sha1_trun
|
9
8
|
|
10
|
-
def initialize
|
9
|
+
def initialize puller, eth, blob, sending_addr, contract_id='', group_id=''
|
10
|
+
@swarm_puller = puller
|
11
|
+
@eth = eth
|
11
12
|
@piecelength = 32 * 1024
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
|
14
|
+
unless blob == nil
|
15
|
+
prepare blob
|
16
|
+
build
|
17
|
+
write_torrent
|
18
|
+
publish_torrent
|
19
|
+
end
|
20
|
+
unless sending_addr == nil
|
21
|
+
publish_ethereum sending_addr, contract_id, group_id
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
private
|
21
26
|
def prepare blob
|
22
27
|
sha1_full = Digest::SHA1.hexdigest blob
|
23
28
|
@sha1_trun = sha1_full[0..23]
|
24
|
-
@tor_file = File.join(TORRENTS_DIR, "#{sha1_trun}.torrent")
|
25
|
-
@blob_file = File.join(BLOBS_DIR, sha1_trun)
|
29
|
+
@tor_file = File.join(ENV['TORRENTS_DIR'], "#{sha1_trun}.torrent")
|
30
|
+
@blob_file = File.join(ENV['BLOBS_DIR'], sha1_trun)
|
26
31
|
File.open(@blob_file, 'w'){|f| f.write(blob)}
|
27
32
|
@files = [{ path: @blob_file.split('/'), length: File::open(@blob_file).size }]
|
28
33
|
end
|
@@ -69,8 +74,9 @@ class PublishBlob
|
|
69
74
|
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Torrent Link >> \t" + "#{@tor_file}"
|
70
75
|
end
|
71
76
|
|
72
|
-
def publish_torrent
|
73
|
-
|
77
|
+
def publish_torrent
|
78
|
+
p "#{@swarm_puller}"
|
79
|
+
torrent = @swarm_puller.create @tor_file
|
74
80
|
begin
|
75
81
|
@btih = torrent["torrent-added"]['hashString']
|
76
82
|
rescue
|
@@ -80,23 +86,16 @@ class PublishBlob
|
|
80
86
|
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Magnet Link >> \t" + mag_link
|
81
87
|
end
|
82
88
|
|
83
|
-
def publish_ethereum sending_addr, contract_id,
|
89
|
+
def publish_ethereum sending_addr, contract_id, group_id
|
84
90
|
message = {}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
message['params'] = [
|
91
|
-
sending_addr, #senderaddr
|
92
|
-
'', #value
|
93
|
-
contract_id, #recipientaddr
|
94
|
-
'10000', #gas
|
95
|
-
'3', #dataslots
|
96
|
-
'newp', #....data
|
97
|
-
thread_id,
|
91
|
+
post_id = "0x#{@btih}#{@sha1_trun}"
|
92
|
+
data = [
|
93
|
+
'3', #data_slots
|
94
|
+
'newp', #....data
|
95
|
+
group_id,
|
98
96
|
post_id
|
99
97
|
]
|
100
|
-
@eth.
|
98
|
+
@eth.transact contract_id, sending_addr, data
|
101
99
|
end
|
102
100
|
end
|
101
|
+
|
data/lib/c3d/setup.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'celluloid/autostart'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class SetupC3D
|
6
|
+
include Celluloid
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
set_deps
|
10
|
+
config = get_config
|
11
|
+
set_the_env config
|
12
|
+
set_trans_config config
|
13
|
+
set_c3d_config config
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_deps
|
17
|
+
dep_exist? 'transmission-daemon', 'sudo apt-get install transmission-daemon'
|
18
|
+
dep_exist? 'node', 'sudo apt-get install nodejs'
|
19
|
+
unless File.directory? File.join(File.dirname(__FILE__), '..', '..', 'node_modules', 'c3d')
|
20
|
+
`cd #{File.join(File.dirname(__FILE__), '..', '..')} && npm install c3d`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_config
|
25
|
+
dir_exist? File.join(ENV['HOME'], '.epm')
|
26
|
+
config_file = File.join(ENV['HOME'], '.epm', 'c3d-config.json')
|
27
|
+
config_example = File.join(File.dirname(__FILE__), '..', '..', 'settings', 'c3d-config.json')
|
28
|
+
unless File.exists? config_file
|
29
|
+
FileUtils.cp config_example, config_file
|
30
|
+
end
|
31
|
+
return JSON.load(File.read(config_file))
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_the_env config
|
35
|
+
ENV['SWARM_DIR'] = config['swarm_dir']
|
36
|
+
ENV['TORRENTS_DIR'] = config['torrents_dir']
|
37
|
+
ENV['BLOBS_DIR'] = config['blobs_dir']
|
38
|
+
ENV['WATCH_FILE'] = config['watch_file']
|
39
|
+
ENV['IGNORE_FILE'] = config['ignore_file']
|
40
|
+
ENV['TORRENT_RPC'] = config['torrent_rpc']
|
41
|
+
ENV['TORRENT_USER'] = config['torrent_user']
|
42
|
+
ENV['TORRENT_PASS'] = config['torrent_pass']
|
43
|
+
ENV['UI_ADDRESS'] = config['ui_address']
|
44
|
+
ENV['ETH_ZMQ_ADDR'] = config['eth_zmq_addr']
|
45
|
+
ENV['ETH_HOST'] = config['eth_host']
|
46
|
+
ENV['ETH_PORT'] = config['eth_port']
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_trans_config config
|
50
|
+
trans_file = File.join(ENV['HOME'], '.epm', 'settings.json')
|
51
|
+
trans_example = File.join(File.dirname(__FILE__), '..', '..', 'settings', 'transmission.json')
|
52
|
+
unless File.exists? trans_file
|
53
|
+
FileUtils.cp trans_example, trans_file
|
54
|
+
end
|
55
|
+
trans_config = JSON.load(File.read(trans_file))
|
56
|
+
trans_config["incomplete-dir"] = config['download_dir']
|
57
|
+
trans_config["download-queue-size"] = config['download-queue-size'].to_i
|
58
|
+
trans_config["queue-stalled-minutes"] = config['queue-stalled-minutes'].to_i
|
59
|
+
trans_config["seed-queue-size"] = config['seed-queue-size'].to_i
|
60
|
+
File.open(trans_file, 'w'){|f| f.write(JSON.pretty_generate(trans_config))}
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_c3d_config config
|
64
|
+
dir_exist? ENV['SWARM_DIR']
|
65
|
+
dir_exist? ENV['TORRENTS_DIR']
|
66
|
+
dir_exist? ENV['BLOBS_DIR']
|
67
|
+
dir_exist? config['download_dir']
|
68
|
+
file_exist? ENV['WATCH_FILE']
|
69
|
+
file_exist? ENV['IGNORE_FILE']
|
70
|
+
end
|
71
|
+
|
72
|
+
def dir_exist? directry
|
73
|
+
unless File.directory? directry
|
74
|
+
Dir.mkdir directry
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def file_exist? fil
|
79
|
+
unless File.exists? fil
|
80
|
+
File.open(fil, "w") {}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def dep_exist? dependency, fixer
|
85
|
+
unless which dependency
|
86
|
+
`#{fixer}`
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def which cmd
|
91
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
92
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
93
|
+
exts.each { |ext|
|
94
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
95
|
+
return exe if File.executable? exe
|
96
|
+
}
|
97
|
+
end
|
98
|
+
return nil
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if __FILE__==$0
|
103
|
+
require 'json'
|
104
|
+
SetupC3D.new
|
105
|
+
end
|
data/lib/c3d/subscribe.rb
CHANGED
@@ -7,28 +7,72 @@
|
|
7
7
|
# * `unsubscribe-g` remove a group's blobs from the subscribed list (params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
8
8
|
# * `ignore-g` add a group to the ignore list (params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
9
9
|
|
10
|
-
|
10
|
+
require 'json'
|
11
|
+
require 'celluloid/autostart'
|
12
|
+
require 'base64'
|
13
|
+
|
14
|
+
class Subscribe
|
11
15
|
include Celluloid
|
12
16
|
attr_accessor :tor_file, :blob_file, :sha1_trun
|
13
17
|
|
14
|
-
def initialize action
|
18
|
+
def initialize action, eth
|
19
|
+
@eth = eth
|
15
20
|
case action
|
16
|
-
when '
|
21
|
+
when 'subscribeK'
|
17
22
|
subscribe_k
|
18
|
-
when '
|
23
|
+
when 'subscribeG'
|
19
24
|
subscribe_g
|
20
|
-
when '
|
25
|
+
when 'unsubscribeK'
|
21
26
|
unsubscribe_k
|
22
|
-
when '
|
27
|
+
when 'unsubscribeG'
|
23
28
|
unsubscribe_g
|
24
|
-
when '
|
29
|
+
when 'ignoreG'
|
25
30
|
ignore_g
|
26
|
-
when '
|
31
|
+
when 'assembleQueries'
|
27
32
|
assemble_queries
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
36
|
def assemble_queries
|
37
|
+
# watched, ignored = load_library
|
38
|
+
# watched[contract] = [group1,group2] || watched[contract]=[] <=all
|
39
|
+
watched = {"97d1f086800920e8fd2344be52fb22d7bf6036d2" => []}
|
40
|
+
watched.each_key do |contract|
|
41
|
+
# todo - build
|
42
|
+
latest_group = send_query contract, '0x18'
|
43
|
+
latest_group_author = send_query contract, latest_group
|
44
|
+
step = iterate latest_group
|
45
|
+
prev_group = send_query contract, step # prev_group == '0x16' => first_group
|
46
|
+
step = iterate step
|
47
|
+
next_group = send_query contract, step # next_group == '0x' => last_group
|
48
|
+
step = iterate step
|
49
|
+
title1 = send_query contract, step
|
50
|
+
step = iterate step
|
51
|
+
title2 = send_query contract, step
|
52
|
+
title = eth_strings title1
|
53
|
+
title << eth_strings(title2) unless title2 == '0x'
|
54
|
+
step = iterate step
|
55
|
+
posts_in_group = (send_query contract, step).to_i(16)
|
56
|
+
step = iterate step
|
57
|
+
latest_blob = send_query contract, step
|
58
|
+
p latest_group
|
59
|
+
p latest_group_author
|
60
|
+
p next_group
|
61
|
+
p prev_group
|
62
|
+
p title
|
63
|
+
p posts_in_group
|
64
|
+
p latest_blob
|
65
|
+
next_blob = ''
|
66
|
+
until next_blob == '0x'
|
67
|
+
next_blob = send_query contract, latest_blob
|
68
|
+
latest_blob_author = send_query contract, latest_blob.next
|
69
|
+
blob_id = send_query contract, latest_blob.next.next
|
70
|
+
p next_blob
|
71
|
+
p latest_blob_author
|
72
|
+
get_the_blob blob_id unless do_i_have_it? blob_id
|
73
|
+
latest_blob = next_blob
|
74
|
+
end
|
75
|
+
end
|
32
76
|
#read watcher file && build hash
|
33
77
|
#read igored file && delete from hash
|
34
78
|
#for each watched contract
|
@@ -40,4 +84,55 @@ class Subscriber
|
|
40
84
|
#if that number has changed, loop through the posts and check that each
|
41
85
|
end
|
42
86
|
|
87
|
+
private
|
88
|
+
|
89
|
+
def load_library
|
90
|
+
watched = JSON.load File.read ENV['WATCH_FILE']
|
91
|
+
ignored = JSON.load File.read ENV['IGNORE_FILE']
|
92
|
+
[watched, ignored]
|
93
|
+
end
|
94
|
+
|
95
|
+
def send_query contract, storage
|
96
|
+
@eth.get_storage_at contract, storage
|
97
|
+
end
|
98
|
+
|
99
|
+
def eth_strings input
|
100
|
+
input.scan(/../).map{|x| x.hex }.reject{|c| c == 0}.pack('c*')
|
101
|
+
end
|
102
|
+
|
103
|
+
def iterate input
|
104
|
+
last_place = input[-1]
|
105
|
+
input[-1] = last_place.next
|
106
|
+
input
|
107
|
+
end
|
108
|
+
|
109
|
+
def do_i_have_it? blob
|
110
|
+
dn = blob[42..-1]
|
111
|
+
p 'dont have this'
|
112
|
+
File.exists?(File.join(ENV['BLOBS_DIR'], dn))
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_the_blob blob
|
116
|
+
btih = blob[2..41]
|
117
|
+
dn = blob[42..-1]
|
118
|
+
link = "magnet:?xt=urn:btih:" + btih + "&dn=" + dn
|
119
|
+
p 'getting_link'
|
120
|
+
torrent = @@swarm_puller.create link
|
121
|
+
p torrent
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if __FILE__==$0
|
126
|
+
require './connect_ethereum.rb'
|
127
|
+
require './connect_torrent'
|
128
|
+
require 'yaml'
|
129
|
+
require 'httparty'
|
130
|
+
@@swarm_puller = TorrentAPI.new(
|
131
|
+
username: ENV['TORRENT_USER'],
|
132
|
+
password: ENV['TORRENT_PASS'],
|
133
|
+
url: ENV['TORRENT_RPC'],
|
134
|
+
debug_mode: true
|
135
|
+
)
|
136
|
+
questions_for_eth = ConnectEth.new :zmq, :cpp
|
137
|
+
Subscribe.new 'assembleQueries', questions_for_eth
|
43
138
|
end
|
data/lib/c3d/util.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# based off of work by @mukaibot here: https://github.com/mukaibot/mktorrent/blob/master/lib/mktorrent.rb
|
3
|
+
# and work by @Burgestrand here: https://gist.github.com/Burgestrand/1733611
|
4
|
+
# note `rhash` dependency
|
5
|
+
|
6
|
+
module Utility
|
7
|
+
def self.add_group_to_ethereum sending_addr, contract_id, title, eth
|
8
|
+
message = {}
|
9
|
+
message['command'] = 'transact'
|
10
|
+
message['params'] = [
|
11
|
+
sending_addr, #sender_addr
|
12
|
+
'', #value
|
13
|
+
contract_id, #recipient_addr
|
14
|
+
'10000', #gas
|
15
|
+
'2', #data_slots
|
16
|
+
'newt', #....data
|
17
|
+
title
|
18
|
+
]
|
19
|
+
eth.write JSON.dump message
|
20
|
+
### somehow this is not currently working.
|
21
|
+
end
|
22
|
+
end
|
data/lib/c3d/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
VERSION = "0.3.
|
1
|
+
VERSION = "0.3.5"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"swarm_dir": "/home/coda/.cache/c3d",
|
3
|
+
"torrents_dir": "/home/coda/.cache/c3d/torrents",
|
4
|
+
"blobs_dir": "/home/coda/.cache/c3d/blobs",
|
5
|
+
"watch_file": "/home/coda/.cache/c3d/watchers.json",
|
6
|
+
"torrent_rpc": "http://127.0.0.1:9091/transmission/rpc",
|
7
|
+
"torrent_user": "username",
|
8
|
+
"torrent_pass": "password",
|
9
|
+
"ui_address": "tcp://127.0.0.1:31314",
|
10
|
+
"eth_zmq_addr": "tcp://127.0.0.1:31315",
|
11
|
+
"eth_host": "localhost",
|
12
|
+
"eth_port": "9090",
|
13
|
+
"ignore_file": "/home/coda/.cache/c3d/ignored.json",
|
14
|
+
"download_dir": "/home/coda/.cache/c3d/downloading",
|
15
|
+
"download-queue-size": "50",
|
16
|
+
"queue-stalled-minutes": "98"
|
17
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
{
|
2
|
+
"alt-speed-down": 50,
|
3
|
+
"alt-speed-enabled": false,
|
4
|
+
"alt-speed-time-begin": 540,
|
5
|
+
"alt-speed-time-day": 127,
|
6
|
+
"alt-speed-time-enabled": false,
|
7
|
+
"alt-speed-time-end": 1020,
|
8
|
+
"alt-speed-up": 50,
|
9
|
+
"bind-address-ipv4": "0.0.0.0",
|
10
|
+
"bind-address-ipv6": "::",
|
11
|
+
"blocklist-enabled": false,
|
12
|
+
"blocklist-url": "http://www.example.com/blocklist",
|
13
|
+
"cache-size-mb": 4,
|
14
|
+
"dht-enabled": true,
|
15
|
+
"download-dir": "/home/coda/.cache/c3d/blobs",
|
16
|
+
"download-queue-enabled": true,
|
17
|
+
"download-queue-size": 50,
|
18
|
+
"encryption": 2,
|
19
|
+
"idle-seeding-limit": 30,
|
20
|
+
"idle-seeding-limit-enabled": false,
|
21
|
+
"incomplete-dir": "/home/coda/.cache/c3d/downloading",
|
22
|
+
"incomplete-dir-enabled": false,
|
23
|
+
"lpd-enabled": false,
|
24
|
+
"message-level": 2,
|
25
|
+
"peer-congestion-algorithm": "",
|
26
|
+
"peer-id-ttl-hours": 6,
|
27
|
+
"peer-limit-global": 200,
|
28
|
+
"peer-limit-per-torrent": 50,
|
29
|
+
"peer-port": 51413,
|
30
|
+
"peer-port-random-high": 65535,
|
31
|
+
"peer-port-random-low": 49152,
|
32
|
+
"peer-port-random-on-start": false,
|
33
|
+
"peer-socket-tos": "default",
|
34
|
+
"pex-enabled": true,
|
35
|
+
"port-forwarding-enabled": true,
|
36
|
+
"preallocation": 1,
|
37
|
+
"prefetch-enabled": 1,
|
38
|
+
"queue-stalled-enabled": true,
|
39
|
+
"queue-stalled-minutes": 98,
|
40
|
+
"ratio-limit": 2,
|
41
|
+
"ratio-limit-enabled": false,
|
42
|
+
"rename-partial-files": true,
|
43
|
+
"rpc-authentication-required": false,
|
44
|
+
"rpc-bind-address": "0.0.0.0",
|
45
|
+
"rpc-enabled": true,
|
46
|
+
"rpc-password": "{e2f58ad4b908bfce4bc698c730b5b49e2cceea26.21gDuIy",
|
47
|
+
"rpc-port": 9091,
|
48
|
+
"rpc-url": "/transmission/",
|
49
|
+
"rpc-username": "",
|
50
|
+
"rpc-whitelist": "127.0.0.1",
|
51
|
+
"rpc-whitelist-enabled": true,
|
52
|
+
"scrape-paused-torrents-enabled": true,
|
53
|
+
"script-torrent-done-enabled": false,
|
54
|
+
"script-torrent-done-filename": "",
|
55
|
+
"seed-queue-enabled": false,
|
56
|
+
"seed-queue-size": 0,
|
57
|
+
"speed-limit-down": 100,
|
58
|
+
"speed-limit-down-enabled": false,
|
59
|
+
"speed-limit-up": 100,
|
60
|
+
"speed-limit-up-enabled": false,
|
61
|
+
"start-added-torrents": true,
|
62
|
+
"trash-original-torrent-files": false,
|
63
|
+
"umask": 18,
|
64
|
+
"upload-slots-per-torrent": 14,
|
65
|
+
"utp-enabled": true,
|
66
|
+
"watch-dir-enabled": false
|
67
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: c3d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Casey Kuhlman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -82,16 +82,20 @@ files:
|
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
84
|
- c3d.gemspec
|
85
|
-
- ethereum_bridge.js
|
86
85
|
- lib/c3d.rb
|
87
|
-
- lib/c3d/
|
86
|
+
- lib/c3d/connect_ethereum_rpc.rb
|
87
|
+
- lib/c3d/connect_ethereum_socket.rb
|
88
88
|
- lib/c3d/connect_torrent.rb
|
89
89
|
- lib/c3d/connect_ui.rb
|
90
90
|
- lib/c3d/get.rb
|
91
|
+
- lib/c3d/processes.rb
|
91
92
|
- lib/c3d/publish.rb
|
93
|
+
- lib/c3d/setup.rb
|
92
94
|
- lib/c3d/subscribe.rb
|
95
|
+
- lib/c3d/util.rb
|
93
96
|
- lib/c3d/version.rb
|
94
|
-
-
|
97
|
+
- settings/c3d-config.json
|
98
|
+
- settings/transmission.json
|
95
99
|
- spec/checker.rb
|
96
100
|
- spec/checker2.rb
|
97
101
|
- spec/tmp
|
data/ethereum_bridge.js
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
var strftime = require('strftime');
|
2
|
-
|
3
|
-
var c3dAddress = 'tcp://127.0.0.1:31315';
|
4
|
-
|
5
|
-
var zeromq = require('zmq');
|
6
|
-
var c3dSocket = zeromq.socket('rep');
|
7
|
-
c3dSocket.identity = 'uiResponder' + process.pid;
|
8
|
-
|
9
|
-
var ethBridge = require('socket.io').listen(31313);
|
10
|
-
|
11
|
-
if (!Array.prototype.last){
|
12
|
-
Array.prototype.last = function(){
|
13
|
-
return this[this.length - 1];
|
14
|
-
};
|
15
|
-
};
|
16
|
-
|
17
|
-
console.log( "[C3D-EPM::" + strftime('%F %T', new Date()) + "] eth<-c3d on port >>\t" + c3dAddress.split(':').last() );
|
18
|
-
|
19
|
-
c3dSocket.bind(c3dAddress, function(err) {
|
20
|
-
if (err) throw err;
|
21
|
-
ethBridge.sockets.on('connection', function(ethBridgeSocket) {
|
22
|
-
|
23
|
-
c3dSocket.on('message', function(data) {
|
24
|
-
|
25
|
-
var self = this;
|
26
|
-
var question = JSON.parse(data.toString());
|
27
|
-
console.log( "[C3D-EPM::" + strftime('%F %T', new Date()) + "] Question asked >>\t" + question.command );
|
28
|
-
|
29
|
-
if ( question.command == 'c3dRequestsAddBlob') {
|
30
|
-
ethBridgeSocket.emit('transact', question.params);
|
31
|
-
|
32
|
-
ethBridgeSocket.on('transact', function(response) {
|
33
|
-
respond(response,c3dSocket);
|
34
|
-
});
|
35
|
-
} else if ( question.command == 'c3dRequestsAddresses' ) {
|
36
|
-
ethBridgeSocket.emit('getAddresses');
|
37
|
-
|
38
|
-
ethBridgeSocket.on('getAddresses', function(response) {
|
39
|
-
respond(response,c3dSocket);
|
40
|
-
});
|
41
|
-
} else if ( question.command == 'c3dRequestsStorage') {
|
42
|
-
ethBridgeSocket.emit('getStorageAt', question.params);
|
43
|
-
|
44
|
-
ethBridgeSocket.on('getStorageAt', function(response) {
|
45
|
-
respond(response, c3dSocket);
|
46
|
-
});
|
47
|
-
};
|
48
|
-
});
|
49
|
-
});
|
50
|
-
});
|
51
|
-
|
52
|
-
respond = function(response, c3dSocket) {
|
53
|
-
answer = {success: 'true', answer: response};
|
54
|
-
console.log( "[C3D-EPM::" + strftime('%F %T', new Date()) + "] Sending answer >>\t" + answer.success );
|
55
|
-
c3dSocket.send(JSON.stringify(answer));
|
56
|
-
};
|
57
|
-
|
58
|
-
process.on('SIGINT', function() {
|
59
|
-
c3dSocket.close();
|
60
|
-
ethBridge.socket.close();
|
61
|
-
});
|
data/lib/c3d/connect_ethereum.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Transactions:
|
4
|
-
# * `add-blob-to-g`: add blob to group (params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
5
|
-
# * `rm-blob-from-g`: remove blob from contract (params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
6
|
-
|
7
|
-
require 'json'
|
8
|
-
require 'celluloid/zmq'
|
9
|
-
|
10
|
-
Celluloid::ZMQ.init
|
11
|
-
|
12
|
-
class ConnectEth
|
13
|
-
include Celluloid::ZMQ
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@question_socket = ReqSocket.new
|
17
|
-
begin
|
18
|
-
@question_socket.connect ETH_ADDRESS
|
19
|
-
rescue IOError
|
20
|
-
@question_socket.close
|
21
|
-
end
|
22
|
-
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] c3D->eth on port >>\t#{ETH_ADDRESS.split(':').last}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def write message
|
26
|
-
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Sending Question >>\t#{message}"
|
27
|
-
@question_socket.send message
|
28
|
-
handle_response JSON.load(@question_socket.read)
|
29
|
-
end
|
30
|
-
|
31
|
-
def handle_response response
|
32
|
-
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Received Answer >>\tsuccess:#{response['success']}\tanswer:#{response['answer']}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
if __FILE__==$0
|
37
|
-
ETH_ADDRESS = 'tcp://127.0.0.1:31315'
|
38
|
-
|
39
|
-
message = {}
|
40
|
-
message['command'] = 'c3dRequestsAddBlob'
|
41
|
-
message['params'] = [
|
42
|
-
'a6cb63ec28c12929bee2d3567bf98f374a0b7167', #senderaddr
|
43
|
-
'', #value
|
44
|
-
'd00383d79aaede0ed34fab69e932a878e00a8938', #recipientaddr
|
45
|
-
'10000', #gas
|
46
|
-
'3', #dataslots
|
47
|
-
'newp', #....data
|
48
|
-
'0x2A519DE3379D1192150778F9A6B1F1FFD8EF0EDAC9C91FA7E6F1853700600000',
|
49
|
-
'0x1d822cb2e4c60c3a8a85546304072b14fb9de94e2c0c608c4120b5d529590c9d'
|
50
|
-
]
|
51
|
-
questions_for_eth = ConnectEth.new
|
52
|
-
questions_for_eth.write JSON.dump message
|
53
|
-
|
54
|
-
message = {}
|
55
|
-
message['command'] = 'c3dRequestsAddresses'
|
56
|
-
questions_for_eth.write JSON.dump message
|
57
|
-
|
58
|
-
message = {}
|
59
|
-
message['command'] = 'c3dRequestsStorage'
|
60
|
-
message['params'] = [
|
61
|
-
'd00383d79aaede0ed34fab69e932a878e00a8938',
|
62
|
-
'0x2A519DE3379D1192150778F9A6B1F1FFD8EF0EDAC9C91FA7E6F1853700600003'
|
63
|
-
]
|
64
|
-
questions_for_eth.write JSON.dump message
|
65
|
-
|
66
|
-
sleep
|
67
|
-
end
|
data/lib/system-setup.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
def check_system
|
4
|
-
|
5
|
-
# Check for the SWARM_DIR Directory
|
6
|
-
unless File.directory?(SWARM_DIR)
|
7
|
-
Dir.mkdir SWARM_DIR
|
8
|
-
end
|
9
|
-
|
10
|
-
# Check for the TORRENTS_DIR Directory
|
11
|
-
unless File.directory?(TORRENTS_DIR)
|
12
|
-
Dir.mkdir TORRENTS_DIR
|
13
|
-
end
|
14
|
-
|
15
|
-
# Check for the BLOBS_DIR Directory
|
16
|
-
unless File.directory?(BLOBS_DIR)
|
17
|
-
Dir.mkdir BLOBS_DIR
|
18
|
-
end
|
19
|
-
|
20
|
-
# Check Ruby Bundled Assets & Set Asset Paths
|
21
|
-
unless system 'bundle check > /dev/null'
|
22
|
-
p 'Bundle is not installed. Installing now....'
|
23
|
-
system 'rake install'
|
24
|
-
p 'I have installed everything, but I need you to restart me'
|
25
|
-
return false
|
26
|
-
end
|
27
|
-
|
28
|
-
p "System all setup and Ready."
|
29
|
-
end
|
30
|
-
|
31
|
-
def which cmd
|
32
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
33
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
34
|
-
exts.each { |ext|
|
35
|
-
exe = File.join(path, "#{cmd}#{ext}")
|
36
|
-
return exe if File.executable? exe
|
37
|
-
}
|
38
|
-
end
|
39
|
-
return nil
|
40
|
-
end
|