c3d 0.4.3 → 0.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cba87cfada3d0f209978c188472b608ca9b5ed4d
4
- data.tar.gz: a6fb9de8ad38c14c5bdc54e9256a1643f280e800
3
+ metadata.gz: 6cd7c5c2ac990aa936c937472a9b113bcbaadd3f
4
+ data.tar.gz: 48b40486ae1b6e22e51ef0d1c37cba2ccc23bcab
5
5
  SHA512:
6
- metadata.gz: 2a768247dc03572a96150790826ecc29f6e980df222e712eb04119a0af74afbb1009064423cedc7471c11464788b01e06ad7b46a18dd3db7ad794a03aac76525
7
- data.tar.gz: 0f554543ddd4f1bef4e66944ea80bac244f301f8cc94edac0381e2aa56ba09b5914c623e289c56bf7a645a29bc37e359f9b893d44f3f095662835bf758b13c09
6
+ metadata.gz: bf6bc805aaaa88c9a2efed4bd89f05e281eb0d01af1144077898ed2255694778e8552c0232f4715ec3e093cb055fa5156abb75c5cdcb36a5b857c7d7bcccd239
7
+ data.tar.gz: ea59eda6d8a2691771667bcade3f93f3b8db42f3987e58aa751a7b85da95db35570635e214503d9506137b0228066f5caf56c36898a31ce838658679de41701d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- c3d (0.3.5)
4
+ c3d (0.4.3)
5
5
  bencode (~> 0.8)
6
6
  celluloid (~> 0.15)
7
7
  commander (~> 4.1)
@@ -16,7 +16,7 @@ GEM
16
16
  commander (4.1.6)
17
17
  highline (~> 1.6.11)
18
18
  diff-lcs (1.2.5)
19
- epm (0.3.7)
19
+ epm (0.3.8)
20
20
  commander (~> 4.1.6)
21
21
  highline (1.6.21)
22
22
  httparty (0.13.1)
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module C3D
4
+ class Assemble
5
+ attr_reader :content
6
+
7
+ def initialize contract
8
+ @content = []
9
+ assemble_and_perform_queries contract
10
+ end
11
+
12
+ private
13
+
14
+ def assemble_and_perform_queries contract
15
+ contract = address_guard contract
16
+ puts "[C3D::#{Time.now.strftime( "%F %T" )}] Assembling >>\t" + contract
17
+ get_the_contract contract
18
+ end
19
+
20
+ def get_the_contract contract
21
+ if ab? contract
22
+ get_ab_content contract
23
+ elsif ba? contract
24
+ get_ba_content contract
25
+ end
26
+ end
27
+
28
+ def get_ab_content contract
29
+ if can_we_get_the_k? contract
30
+ blob = send_query contract, '0x13'
31
+ get_the_blob blob, contract
32
+ end
33
+ end
34
+
35
+ def get_ba_content contract
36
+ if can_we_get_the_k? contract
37
+ group = {}
38
+ group[:prev] = send_query contract, '0x19'
39
+ until group[:prev] == '0x30'
40
+ group = get_the_group contract, group[:prev]
41
+ get_the_blob group[:blob], group[:this] if group[:blob]
42
+ end
43
+ end
44
+ end
45
+
46
+ def can_we_get_the_k? contract
47
+ behav = send_query contract, '0x18'
48
+ if behav == ('0x01' || '0x1')
49
+ return true
50
+ end
51
+ return false
52
+ end
53
+
54
+ def get_the_group contract, group_id
55
+ this_group = {}
56
+ this_group[:this] = group_id
57
+ if can_we_get_the_group? contract, group_id
58
+ this_group[:blob] = send_query(contract, content_slot(group_id))
59
+ this_group[:prev] = send_query(contract, prev_link_slot(group_id))
60
+ else
61
+ this_group[:prev] = send_query(contract, prev_link_slot(group_id))
62
+ end
63
+ return this_group
64
+ end
65
+
66
+ def can_we_get_the_group? contract, group_id
67
+ behav = send_query(contract, behav_slot(group_id))
68
+ if behav == ('0x01' || '0x1' || '0x')
69
+ return true
70
+ end
71
+ return false
72
+ end
73
+
74
+ def does_the_group_have_blobs? contract, group_id
75
+ type = send_query(contract, type_slot(group_id))
76
+ if type == ('0x01' || '0x1')
77
+ return true
78
+ end
79
+ return false
80
+ end
81
+
82
+ def send_query contract, storage
83
+ $eth.get_storage_at contract, storage
84
+ end
85
+
86
+ def ab? contract
87
+ location = send_query contract, '0x10'
88
+ if location == '0x88554646ab'
89
+ return true
90
+ else
91
+ return false
92
+ end
93
+ end
94
+
95
+ def ba? contract
96
+ location = send_query contract, '0x10'
97
+ if location == '0x88554646ba'
98
+ return true
99
+ else
100
+ return false
101
+ end
102
+ end
103
+
104
+ def get_the_blob blob, contract
105
+ begin
106
+ dn = blob[42..-1]
107
+ blob_file = File.join(ENV['BLOBS_DIR'], dn)
108
+ if File.exists? blob_file
109
+ blob = File.read blob_file
110
+ sha1_full = Digest::SHA1.hexdigest blob
111
+ sha1_trun = sha1_full[0..23]
112
+ if sha1_trun == dn
113
+ @content << { contract => blob }
114
+ puts "[C3D::#{Time.now.strftime( "%F %T" )}] Assembling >>\t" + contract
115
+ return true
116
+ end
117
+ end
118
+ return false
119
+ rescue
120
+ return false
121
+ end
122
+ end
123
+
124
+ def prev_link_slot group_id
125
+ slot = "0x" + ((group_id.hex + 0x1).to_s(16))
126
+ end
127
+
128
+ def type_slot group_id
129
+ slot = "0x" + ((group_id.hex + 0x3).to_s(16))
130
+ end
131
+
132
+ def behav_slot group_id
133
+ slot = "0x" + ((group_id.hex + 0x4).to_s(16))
134
+ end
135
+
136
+ def content_slot group_id
137
+ slot = "0x" + ((group_id.hex + 0x5).to_s(16))
138
+ end
139
+
140
+ def address_guard contract
141
+ contract = "0x#{contract}" unless contract[0..1] == '0x'
142
+ end
143
+ end
144
+ end
@@ -11,7 +11,7 @@ module C3D
11
11
  @request = Net::HTTP::Post.new @uri.request_uri
12
12
  @request.content_type = 'application/json'
13
13
  @last_push = Time.now
14
- puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] c3D->eth via RPC on port >>\t#{ENV['ETH_PORT']}"
14
+ puts "[C3D::#{Time.now.strftime( "%F %T" )}] c3D->eth via RPC on port >>\t#{ENV['ETH_PORT']}"
15
15
  end
16
16
 
17
17
  def get_storage_at address, storage_location
@@ -129,16 +129,16 @@ module C3D
129
129
 
130
130
  def send_command request
131
131
  @request.body = request.to_json
132
- puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Sending Question >>\t#{@request.body}"
132
+ puts "[C3D::#{Time.now.strftime( "%F %T" )}] Sending Question >>\t#{@request.body}"
133
133
  handle_response JSON.parse(@question_socket.request(@request).body)
134
134
  end
135
135
 
136
136
  def handle_response response
137
137
  unless response["error"]
138
- puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Received Answer >>\tanswer:#{response['result']}"
138
+ puts "[C3D::#{Time.now.strftime( "%F %T" )}] Received Answer >>\tanswer:#{response['result']}"
139
139
  return response["result"]
140
140
  else
141
- puts "[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Received Answer >>\tERROR!"
141
+ puts "[C3D::#{Time.now.strftime( "%F %T" )}] Received Answer >>\tERROR!"
142
142
  return nil
143
143
  end
144
144
  end
@@ -23,7 +23,7 @@ module C3D
23
23
  end
24
24
 
25
25
  def all
26
- log ("[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Getting All Torrents"), true
26
+ log ("[C3D::#{Time.now.strftime( "%F %T" )}] Getting All Torrents"), true
27
27
 
28
28
  response =
29
29
  post(
@@ -37,7 +37,7 @@ module C3D
37
37
  end
38
38
 
39
39
  def find id
40
- log ("[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Getting Torrent ID >> "+ "#{id}"), true
40
+ log ("[C3D::#{Time.now.strftime( "%F %T" )}] Getting Torrent ID >> "+ "#{id}"), true
41
41
 
42
42
  response =
43
43
  post(
@@ -52,7 +52,7 @@ module C3D
52
52
  end
53
53
 
54
54
  def create filename
55
- log ("[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Adding Blob >>\t\t"+ "#{filename}"), true
55
+ log ("[C3D::#{Time.now.strftime( "%F %T" )}] Adding Blob >>\t\t"+ "#{filename}"), true
56
56
 
57
57
  response =
58
58
  post(
@@ -68,7 +68,7 @@ module C3D
68
68
  end
69
69
 
70
70
  def destroy id
71
- log ("[C3D-EPM::#{Time.now.strftime( "%F %T" )}] Remove Torrent ID >> "+ "#{id}"), true
71
+ log ("[C3D::#{Time.now.strftime( "%F %T" )}] Remove Torrent ID >> "+ "#{id}"), true
72
72
 
73
73
  response =
74
74
  post(
data/lib/c3d/version.rb CHANGED
@@ -1 +1 @@
1
- VERSION ||= "0.4.3"
1
+ VERSION ||= "0.4.4"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c3d
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Casey Kuhlman
@@ -113,6 +113,7 @@ files:
113
113
  - bin/c3d
114
114
  - c3d.gemspec
115
115
  - lib/c3d.rb
116
+ - lib/c3d/actors/assemble.rb
116
117
  - lib/c3d/actors/blacklist.rb
117
118
  - lib/c3d/actors/crawler.rb
118
119
  - lib/c3d/actors/getter.rb