c3d 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +46 -0
- data/Rakefile +8 -1
- data/c3d.gemspec +2 -0
- data/ethereum_bridge.js +61 -0
- data/lib/c3d.rb +22 -31
- data/lib/c3d/connect_ethereum.rb +67 -1
- data/lib/c3d/connect_torrent.rb +25 -10
- data/lib/c3d/connect_ui.rb +52 -0
- data/lib/c3d/get.rb +0 -0
- data/lib/c3d/publish.rb +32 -9
- data/lib/c3d/subscribe.rb +43 -1
- data/lib/c3d/version.rb +1 -1
- data/lib/system-setup.rb +40 -0
- metadata +35 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6de051d34428c13ea6c90d39d7addce37f80172
|
4
|
+
data.tar.gz: 753534010b413309538c3e119e8af08bf3b5f9f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d37975203c97db0df3629a054e1dc641418345ca67f2507e0a7b14585f3e2d52385f5a244a6f58db32ef9864de5afd328f838e7c773701449da3765d96712e9
|
7
|
+
data.tar.gz: 0d4dc7cab886f9aaf84aa2d24ed56b543ae358dbd53aabb0d74993c77213f897d4144ae136585f71e6d21216eb2db9a30228b111a9a32d118a67f530c4db94cd
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
c3d (0.2.0)
|
5
|
+
bencode (~> 0.8)
|
6
|
+
celluloid (~> 0.15)
|
7
|
+
celluloid-zmq (~> 0.15)
|
8
|
+
httparty (~> 0.13)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
bencode (0.8.1)
|
14
|
+
celluloid (0.15.2)
|
15
|
+
timers (~> 1.1.0)
|
16
|
+
celluloid-zmq (0.15.0)
|
17
|
+
celluloid (>= 0.13.0)
|
18
|
+
ffi
|
19
|
+
ffi-rzmq
|
20
|
+
dotenv (0.7.0)
|
21
|
+
ffi (1.9.3)
|
22
|
+
ffi-rzmq (2.0.1)
|
23
|
+
ffi-rzmq-core (>= 1.0.1)
|
24
|
+
ffi-rzmq-core (1.0.3)
|
25
|
+
ffi (~> 1.9)
|
26
|
+
foreman (0.67.0)
|
27
|
+
dotenv (~> 0.7.0)
|
28
|
+
thor (~> 0.17.0)
|
29
|
+
httparty (0.13.1)
|
30
|
+
json (~> 1.8)
|
31
|
+
multi_xml (>= 0.5.2)
|
32
|
+
json (1.8.1)
|
33
|
+
multi_xml (0.5.5)
|
34
|
+
thor (0.17.0)
|
35
|
+
timers (1.1.0)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bencode (~> 0.8)
|
42
|
+
c3d!
|
43
|
+
celluloid (~> 0.15)
|
44
|
+
celluloid-zmq (~> 0.15)
|
45
|
+
foreman
|
46
|
+
httparty (~> 0.13)
|
data/Rakefile
CHANGED
data/c3d.gemspec
CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.add_runtime_dependency 'httparty', '~> 0.13'
|
24
24
|
s.add_runtime_dependency 'bencode', '~> 0.8'
|
25
|
+
s.add_runtime_dependency 'celluloid', '~> 0.15'
|
26
|
+
s.add_runtime_dependency 'celluloid-zmq', '~> 0.15'
|
25
27
|
|
26
28
|
s.description = <<desc
|
27
29
|
This gem is designed to assist in distribution mangement of content which is controlled by an Ethereum contract.
|
data/ethereum_bridge.js
ADDED
@@ -0,0 +1,61 @@
|
|
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.rb
CHANGED
@@ -8,57 +8,48 @@ require 'yaml'
|
|
8
8
|
# Gem Dependencies
|
9
9
|
require 'httparty'
|
10
10
|
require 'bencode'
|
11
|
+
require 'celluloid/autostart'
|
11
12
|
|
12
13
|
# This Gem
|
14
|
+
require File.join(File.dirname(__FILE__), 'c3d', 'version')
|
13
15
|
require File.join(File.dirname(__FILE__), 'c3d', 'connect_ethereum')
|
14
16
|
require File.join(File.dirname(__FILE__), 'c3d', 'connect_torrent')
|
17
|
+
require File.join(File.dirname(__FILE__), 'c3d', 'connect_ui')
|
15
18
|
require File.join(File.dirname(__FILE__), 'c3d', 'publish')
|
16
19
|
require File.join(File.dirname(__FILE__), 'c3d', 'subscribe')
|
17
|
-
require File.join(File.dirname(__FILE__), 'c3d', '
|
20
|
+
require File.join(File.dirname(__FILE__), 'c3d', 'get')
|
18
21
|
|
19
22
|
# todo - load these variables from a config file in ~/.epm
|
20
23
|
SWARM_DIR = File.join(ENV['HOME'], '.cache', 'c3d')
|
21
24
|
TORRENTS_DIR = File.join(SWARM_DIR, 'torrents')
|
22
25
|
BLOBS_DIR = File.join(SWARM_DIR, 'blobs')
|
23
|
-
TORRENT_RPC =
|
26
|
+
TORRENT_RPC = 'http://127.0.0.1:9091/transmission/rpc'
|
24
27
|
TORRENT_USER = 'username'
|
25
28
|
TORRENT_PASS = 'password'
|
29
|
+
ETH_ADDRESS = 'tcp://127.0.0.1:31315'
|
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')
|
26
33
|
|
27
|
-
# todo - check swarm directories exist
|
28
34
|
# todo - check that torrent manager is running
|
29
35
|
# todo - torrentapis use a 'fairly std' rpc framework, but with different
|
30
36
|
# endpoints. need to test these though
|
37
|
+
# todo - check dependencies are installed: zmq ... transmission
|
38
|
+
# todo - add foreman
|
31
39
|
|
32
40
|
swarm_puller = TorrentAPI.new(
|
33
41
|
username: TORRENT_USER,
|
34
42
|
password: TORRENT_PASS,
|
35
43
|
url: TORRENT_RPC,
|
36
|
-
debug_mode:
|
44
|
+
debug_mode: true
|
37
45
|
)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# torrents.each{|t| p 'name'] }
|
49
|
-
|
50
|
-
# [{"addedDate"=>1400177739,
|
51
|
-
# "files"=>
|
52
|
-
# [{"bytesCompleted"=>31752192,
|
53
|
-
# "length"=>591396864,
|
54
|
-
# "name"=>"ubuntu-14.04-server-amd64.iso"}],
|
55
|
-
# "id"=>1,
|
56
|
-
# "isFinished"=>false,
|
57
|
-
# "name"=>"ubuntu-14.04-server-amd64.iso",
|
58
|
-
# "percentDone"=>0.0536,
|
59
|
-
# "rateDownload"=>706000,
|
60
|
-
# "rateUpload"=>3000,
|
61
|
-
# "totalSize"=>591396864}]
|
62
|
-
|
63
|
-
# swarm_puller.destroy(1)
|
64
|
-
# torrent = swarm_puller.find(1)
|
46
|
+
eth = ConnectEth.new
|
47
|
+
|
48
|
+
if __FILE__==$0
|
49
|
+
if ARGV[0]
|
50
|
+
blob1 = File.read(ARGV[0]) + "\n#{Time.now}"
|
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
|
55
|
+
end
|
data/lib/c3d/connect_ethereum.rb
CHANGED
@@ -1 +1,67 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
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/c3d/connect_torrent.rb
CHANGED
@@ -2,11 +2,8 @@
|
|
2
2
|
# This is based off of work by fguillen for the transmission_api gem here: https://github.com/fguillen/TransmissionApi
|
3
3
|
|
4
4
|
class TorrentAPI
|
5
|
-
|
6
|
-
attr_accessor :url
|
7
|
-
attr_accessor :basic_auth
|
8
|
-
attr_accessor :fields
|
9
|
-
attr_accessor :debug_mode
|
5
|
+
include Celluloid
|
6
|
+
attr_accessor :session_id, :url, :basic_auth, :fields, :debug_mode
|
10
7
|
|
11
8
|
TORRENT_FIELDS = [
|
12
9
|
"id",
|
@@ -16,7 +13,7 @@ class TorrentAPI
|
|
16
13
|
"percentDone",
|
17
14
|
]
|
18
15
|
|
19
|
-
def initialize
|
16
|
+
def initialize opts
|
20
17
|
@url = opts[:url]
|
21
18
|
@fields = opts[:fields] || TORRENT_FIELDS
|
22
19
|
@basic_auth = { :username => opts[:username], :password => opts[:password] } if opts[:username]
|
@@ -39,7 +36,7 @@ class TorrentAPI
|
|
39
36
|
response["arguments"]["torrent-added"]
|
40
37
|
end
|
41
38
|
|
42
|
-
def find
|
39
|
+
def find id
|
43
40
|
log ("[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Getting Torrent ID >> "+ "#{id}"), true
|
44
41
|
|
45
42
|
response =
|
@@ -54,7 +51,7 @@ class TorrentAPI
|
|
54
51
|
response["arguments"]["torrents"].first
|
55
52
|
end
|
56
53
|
|
57
|
-
def create
|
54
|
+
def create filename
|
58
55
|
log ("[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Adding Blob >> \t"+ "#{filename}"), true
|
59
56
|
|
60
57
|
response =
|
@@ -67,7 +64,7 @@ class TorrentAPI
|
|
67
64
|
}
|
68
65
|
)
|
69
66
|
|
70
|
-
response["arguments"]
|
67
|
+
response["arguments"]
|
71
68
|
end
|
72
69
|
|
73
70
|
def destroy(id)
|
@@ -147,4 +144,22 @@ class TorrentAPI
|
|
147
144
|
log headers
|
148
145
|
log "------------------"
|
149
146
|
end
|
150
|
-
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)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'celluloid/zmq'
|
5
|
+
|
6
|
+
# commands - sent over ZMQ but using a standard JSONRPC structure.
|
7
|
+
# * `make-blob`: make blob (params: filename: "FILENAME" || filecontents: "CONTENTS") (returns success: BLOB_ID or error)
|
8
|
+
# * `destroy-blob`: destroy blob (params: blob: "BLOB_ID") (returns success: true or error)
|
9
|
+
# * `add-blob-to-g`: add blob to group (params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
10
|
+
# * `rm-blob-from-g`: remove blob from contract (params: blob: "BLOB_ID", contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
11
|
+
# * `subscribe-k`: add a contract's blobs to the subscribed list (params: contract: "CONTRACT_ADDRESS") (returns success: true or error)
|
12
|
+
# * `subscribe-g`: add a group's blobs to the subscribed list (params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
13
|
+
# * `unsubscribe-k` remove a contract's blobs from the subscribed list (params: contract: "CONTRACT_ADDRESS") (returns success: true or error)
|
14
|
+
# * `unsubscribe-g` remove a group's blobs from the subscribed list (params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
15
|
+
# * `ignore-g` add a group to the ignore list (params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
16
|
+
# * `publish`: sugar for make blob + add to k + (opt) add to g (params: filename: "FILENAME" || filecontents: "CONTENTS", contract: "CONTRACT_ADDRESS", [optional] group: ["GROUP1_ID", "GROUP2_ID", ...]) (returns success: BLOB_ID or error)
|
17
|
+
# * `get`: add a magnet link to the cache (params: id: "BLOB_ID") (returns success: true or error)
|
18
|
+
|
19
|
+
Celluloid::ZMQ.init
|
20
|
+
|
21
|
+
class ConnectUI
|
22
|
+
include Celluloid::ZMQ
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@answer_socket = RepSocket.new
|
26
|
+
|
27
|
+
begin
|
28
|
+
@answer_socket.bind UI_ADDRESS
|
29
|
+
rescue IOError
|
30
|
+
@answer_socket.close
|
31
|
+
raise
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] c3D<-ui on port >>\t#{UI_ADDRESS.split(':').last}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def run
|
38
|
+
loop { async.handle_message @answer_socket.read }
|
39
|
+
self.terminate
|
40
|
+
end
|
41
|
+
|
42
|
+
def handle_message message
|
43
|
+
message = JSON.load message
|
44
|
+
@answer_socket.send(JSON.dump(message))
|
45
|
+
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
|
data/lib/c3d/get.rb
ADDED
File without changes
|
data/lib/c3d/publish.rb
CHANGED
@@ -3,19 +3,18 @@
|
|
3
3
|
# and work by @Burgestrand here: https://gist.github.com/Burgestrand/1733611
|
4
4
|
# note `rhash` dependency
|
5
5
|
|
6
|
-
class
|
6
|
+
class PublishBlob
|
7
|
+
include Celluloid
|
7
8
|
attr_accessor :tor_file, :blob_file, :sha1_trun
|
8
9
|
|
9
|
-
def initialize blob, swarm_puller
|
10
|
-
# @tracker = ''
|
11
|
-
# @defaultdir = ""
|
12
|
-
# @filehashes = []
|
13
|
-
# @size = 0
|
10
|
+
def initialize blob, swarm_puller, eth_connector, sending_addr, contract_id, thread_id
|
14
11
|
@piecelength = 32 * 1024
|
12
|
+
@eth = eth_connector
|
15
13
|
prepare blob
|
16
14
|
build
|
17
15
|
write_torrent
|
18
16
|
publish_torrent swarm_puller
|
17
|
+
publish_ethereum sending_addr, contract_id, thread_id
|
19
18
|
end
|
20
19
|
|
21
20
|
private
|
@@ -46,7 +45,7 @@ class Publish
|
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
|
-
def read_pieces
|
48
|
+
def read_pieces file, length
|
50
49
|
buffer = ""
|
51
50
|
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Hashing Blob >> \t" + "#{file.join("/")}"
|
52
51
|
File.open(file.join("/")) do |fh|
|
@@ -72,8 +71,32 @@ class Publish
|
|
72
71
|
|
73
72
|
def publish_torrent swarm_puller
|
74
73
|
torrent = swarm_puller.create @tor_file
|
75
|
-
|
76
|
-
|
74
|
+
begin
|
75
|
+
@btih = torrent["torrent-added"]['hashString']
|
76
|
+
rescue
|
77
|
+
@btih = torrent["torrent-duplicate"]['hashString']
|
78
|
+
end
|
79
|
+
mag_link = "magnet:?xt=urn:btih:" + @btih + "&dn=" + @sha1_trun
|
77
80
|
puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Magnet Link >> \t" + mag_link
|
78
81
|
end
|
82
|
+
|
83
|
+
def publish_ethereum sending_addr, contract_id, thread_id
|
84
|
+
message = {}
|
85
|
+
sending_addr ||= 'a6cb63ec28c12929bee2d3567bf98f374a0b7167'
|
86
|
+
contract_id ||= 'd00383d79aaede0ed34fab69e932a878e00a8938'
|
87
|
+
thread_id ||= '0x2A519DE3379D1192150778F9A6B1F1FFD8EF0EDAC9C91FA7E6F1853700600000'
|
88
|
+
post_id ||= "0x#{@btih}#{@sha1_trun}"
|
89
|
+
message['command'] = 'c3dRequestsAddBlob'
|
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,
|
98
|
+
post_id
|
99
|
+
]
|
100
|
+
@eth.write JSON.dump message
|
101
|
+
end
|
79
102
|
end
|
data/lib/c3d/subscribe.rb
CHANGED
@@ -1 +1,43 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Queries:
|
4
|
+
# * `subscribe-k`: add a contract's blobs to the subscribed list (params: contract: "CONTRACT_ADDRESS") (returns success: true or error)
|
5
|
+
# * `subscribe-g`: add a group's blobs to the subscribed list (params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
6
|
+
# * `unsubscribe-k` remove a contract's blobs from the subscribed list (params: contract: "CONTRACT_ADDRESS") (returns success: true or error)
|
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
|
+
# * `ignore-g` add a group to the ignore list (params: contract: "CONTRACT_ADDRESS", group: "GROUP_ID") (returns success: true or error)
|
9
|
+
|
10
|
+
class Subscriber
|
11
|
+
include Celluloid
|
12
|
+
attr_accessor :tor_file, :blob_file, :sha1_trun
|
13
|
+
|
14
|
+
def initialize action
|
15
|
+
case action
|
16
|
+
when 'subscribe-k'
|
17
|
+
subscribe_k
|
18
|
+
when 'subscribe-g'
|
19
|
+
subscribe_g
|
20
|
+
when 'unsubscribe-k'
|
21
|
+
unsubscribe_k
|
22
|
+
when 'unsubscribe-g'
|
23
|
+
unsubscribe_g
|
24
|
+
when 'ignore-g'
|
25
|
+
ignore_g
|
26
|
+
when 'assemble-calls'
|
27
|
+
assemble_queries
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def assemble_queries
|
32
|
+
#read watcher file && build hash
|
33
|
+
#read igored file && delete from hash
|
34
|
+
#for each watched contract
|
35
|
+
# for each watched group
|
36
|
+
#first subquery is to group_id + 5 - contains the number of blobs -> compare to stored val in the JSON
|
37
|
+
#if that number is has not changed, check group_id + 6 - contains the newest post -> compare to stored val in the JSON
|
38
|
+
#if that number is the same, do nothing
|
39
|
+
#if that number has changed, check blob_id + 1 - contains next in linked list -> compare to stored val in the JSON
|
40
|
+
#if that number has changed, loop through the posts and check that each
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/lib/c3d/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
VERSION = "0.
|
1
|
+
VERSION = "0.3.0"
|
data/lib/system-setup.rb
ADDED
@@ -0,0 +1,40 @@
|
|
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
|
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.
|
4
|
+
version: 0.3.0
|
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-05-
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: celluloid
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.15'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.15'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: celluloid-zmq
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.15'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.15'
|
41
69
|
description: |2
|
42
70
|
This gem is designed to assist in distribution mangement of content which is controlled by an Ethereum contract.
|
43
71
|
email: caseykuhlman@watershedlegal.com
|
@@ -49,16 +77,21 @@ files:
|
|
49
77
|
- ".ruby-gemset"
|
50
78
|
- ".ruby-version"
|
51
79
|
- Gemfile
|
80
|
+
- Gemfile.lock
|
52
81
|
- LICENSE.md
|
53
82
|
- README.md
|
54
83
|
- Rakefile
|
55
84
|
- c3d.gemspec
|
85
|
+
- ethereum_bridge.js
|
56
86
|
- lib/c3d.rb
|
57
87
|
- lib/c3d/connect_ethereum.rb
|
58
88
|
- lib/c3d/connect_torrent.rb
|
89
|
+
- lib/c3d/connect_ui.rb
|
90
|
+
- lib/c3d/get.rb
|
59
91
|
- lib/c3d/publish.rb
|
60
92
|
- lib/c3d/subscribe.rb
|
61
93
|
- lib/c3d/version.rb
|
94
|
+
- lib/system-setup.rb
|
62
95
|
- spec/checker.rb
|
63
96
|
- spec/checker2.rb
|
64
97
|
- spec/tmp
|