dropzone_ruby 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c19a6591e576becbce95eee6a238525d940238fc
4
- data.tar.gz: 54b5e677b28bdd5825e19400f7c86c0f5b68f9fc
3
+ metadata.gz: 002a3c52fb4d1c4a622a1912b359adeffb2b4d9b
4
+ data.tar.gz: 0d6e7f4f848e95e507eac992dd75596b1e0a9841
5
5
  SHA512:
6
- metadata.gz: 48fe31ddabbd0ccb13dd7af857ad566d7da0c8c1ac54c1c7af6c6aca785018310cc6209918e1f9c1111698e890731b965e4cdcce2da87efb620056f5aa4e7869
7
- data.tar.gz: 0e164617b26aa065bee6a266e45fec20c7e2e7490cbf781fb237fccc4348dc885205c935ae77ffd260292c01de07d46054fb1bbfc593adf18dd8233d6bfae189
6
+ metadata.gz: 730eeb352aa24143eb363539eddc34849b6c7e81479d10275e5744461ce8985770bea4364f051bd498652bfae089f9a64dfef15f6d0cd586213daf203222a6e0
7
+ data.tar.gz: bb721453be95e7e21992a5ce6e8dabf468a83f86ed05695fd0d13e83de9e8ad8d50b1e55e979b46b3b0f70c9b21029ce8a65e841b7ce8c0d118afa9fa1685ef0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dropzone_ruby (0.1.1)
4
+ dropzone_ruby (0.1.2)
5
5
  commander (~> 4.3)
6
6
  counterparty_ruby (~> 1.2)
7
7
  sequel (~> 4.21)
@@ -49,7 +49,7 @@ GEM
49
49
  rspec-support (~> 3.2.0)
50
50
  rspec-support (3.2.2)
51
51
  ruby-rc4 (0.1.5)
52
- sequel (4.25.0)
52
+ sequel (4.26.0)
53
53
  sham (1.1.0)
54
54
  socksify (1.7.0)
55
55
  sqlite3 (1.3.10)
data/README.md CHANGED
@@ -5,7 +5,7 @@ messaging between buyers and sellers, using nothing but the Bitcoin network.
5
5
  Testnet is used for communications. Mainnet is used for the storage of listings,
6
6
  buyer profiles, and reputational events.
7
7
 
8
- [White Paper](http://www.metzdowd.com/pipermail/cryptography/2015-March/025212.html)
8
+ [White Paper](Drop Zone - Whitepaper.pdf)
9
9
 
10
10
  [Rubygems](https://rubygems.org/gems/dropzone_ruby)
11
11
 
@@ -86,5 +86,6 @@ __quia omnis qui se exaltat humiliabitur et qui se humiliat exaltabitur__
86
86
  * The white paper expressed transaction ids as being encoded ints. These are instead encoded as variable length strings.
87
87
 
88
88
  ## Changelog
89
+ * v0.1.2 - Cleaned up the chat listing interface (renamed communication to chat). Fixed issue with new session create
89
90
  * v0.1.1 - Addressed bugs in Listing find and buyer profiles
90
91
  * v0.1 - First Release
@@ -400,11 +400,11 @@ command 'review create' do |c|
400
400
  "The seller's communications skill. Between 0 (worst) to 8 (best)"
401
401
  end
402
402
 
403
- command 'communication list' do |c|
404
- c.when_called DropZoneCommand, :communication_list
403
+ command 'chat list' do |c|
404
+ c.when_called DropZoneCommand, :chat_list
405
405
 
406
406
  c.syntax, c.summary, c.description =
407
- 'dropzone communication list <private_key>',
407
+ 'dropzone chat list <private_key>',
408
408
  'Show all the available communication channels for the given testnet address',
409
409
  multi(<<-eos)
410
410
  This command lists all the conversations that have been initiated and/or
@@ -414,16 +414,16 @@ command 'communication list' do |c|
414
414
 
415
415
  c.example 'List all communication sessions for a testnet address:',
416
416
  multi(<<-eos)
417
- dropzone communication list
417
+ dropzone chat list
418
418
  92UvdTpmxA6cvD6YeJZSiHW8ff8DsZXL2PHZu9Mg7JY3zbaETJw
419
419
  eos
420
420
  end
421
421
 
422
- command 'communication show' do |c|
423
- c.when_called DropZoneCommand, :communication_show
422
+ command 'chat show' do |c|
423
+ c.when_called DropZoneCommand, :chat_show
424
424
 
425
425
  c.syntax, c.summary, c.description =
426
- 'dropzone communication show <private_key> <tx_id>',
426
+ 'dropzone chat show <private_key> <tx_id>',
427
427
  'Show all the available communication channels for the given testnet address',
428
428
  multi(<<-eos)
429
429
  Output a full conversation, start to finish, between the testnet
@@ -432,17 +432,17 @@ command 'communication show' do |c|
432
432
 
433
433
  c.example 'Show the conversation:',
434
434
  multi(<<-eos) % RANDOM_TXID
435
- dropzone communication show
435
+ dropzone chat show
436
436
  92UvdTpmxA6cvD6YeJZSiHW8ff8DsZXL2PHZu9Mg7JY3zbaETJw
437
437
  %s
438
438
  eos
439
439
  end
440
440
 
441
- command 'communication say' do |c|
442
- c.when_called DropZoneCommand, :communication_say
441
+ command 'chat say' do |c|
442
+ c.when_called DropZoneCommand, :chat_say
443
443
 
444
444
  c.syntax, c.summary, c.description =
445
- 'dropzone communication say <private_key> <tx_id> <message>',
445
+ 'dropzone chat say <private_key> <tx_id> <message>',
446
446
  'Communicate to another party in a private/encrypted conversation over testnet.',
447
447
  multi(<<-eos)
448
448
  Append to the conversation <tx_id> at your testnet address <private> key
@@ -451,24 +451,24 @@ command 'communication say' do |c|
451
451
 
452
452
  c.example 'Converse with another user over testnet:',
453
453
  multi(<<-eos) % RANDOM_TXID
454
- dropzone communication say
454
+ dropzone chat say
455
455
  92UvdTpmxA6cvD6YeJZSiHW8ff8DsZXL2PHZu9Mg7JY3zbaETJw
456
456
  %s
457
457
  "Thank you for your Inquiry"
458
458
  eos
459
459
  end
460
460
 
461
- command 'communication new' do |c|
462
- c.when_called DropZoneCommand, :communication_new
461
+ command 'chat new' do |c|
462
+ c.when_called DropZoneCommand, :chat_new
463
463
 
464
464
  c.syntax, c.summary, c.description =
465
- 'dropzone communication new <private_key> <addr>',
465
+ 'dropzone chat new <private_key> <addr>',
466
466
  'Start a new conversation with the person at a given testnet address',
467
467
  multi(<<-eos)
468
468
  Start a conversation between your tesnet <private_key> and the user at
469
469
  the specified testnet address <addr>. An initiation request needs only
470
470
  to be issued by one user, a recipient must reply to that request using
471
- the "communication say" command, in order to authenticate the initiator's
471
+ the "chat say" command, in order to authenticate the initiator's
472
472
  request and perform key exchange. Thereafter, a channel between the two
473
473
  addresses is established, and communications will remain open.
474
474
 
@@ -480,7 +480,7 @@ command 'communication new' do |c|
480
480
 
481
481
  c.example 'Start a conversation:',
482
482
  multi(<<-eos)
483
- dropzone communication new
483
+ dropzone chat new
484
484
  92UvdTpmxA6cvD6YeJZSiHW8ff8DsZXL2PHZu9Mg7JY3zbaETJw
485
485
  mqVRfjepJTxxoDgDt892tCybhmjfKCFNyp
486
486
  eos
@@ -64,6 +64,40 @@ class DropZoneCommand
64
64
  MAX_TABLE_WIDTH = 80
65
65
 
66
66
  class << self
67
+ def local_persistence=(store)
68
+ @local_persistence = store
69
+ end
70
+
71
+ def local_persistence
72
+ unless @local_persistence
73
+ config_dir = File.join(Dir.home, ".dropzone")
74
+ Dir.mkdir config_dir, 0700 unless Dir.exists? config_dir
75
+
76
+ @local_persistence = Sequel.connect('sqlite://%s/dropzone.db' % config_dir )
77
+ end
78
+
79
+ @local_persistence.create_table :communication_keys do
80
+ primary_key :id
81
+ String :sender_addr
82
+ String :receiver_addr
83
+ String :secret
84
+ end unless @local_persistence.table_exists? :communication_keys
85
+
86
+ @local_persistence.create_table :chats do
87
+ primary_key :id
88
+ String :session_txid
89
+ Integer :last_read_message_count
90
+ end unless @local_persistence.table_exists? :chats
91
+
92
+ @local_persistence.create_table :addresses do
93
+ primary_key :id
94
+ String :addr
95
+ String :label
96
+ end unless @local_persistence.table_exists? :addresses
97
+
98
+ @local_persistence
99
+ end
100
+
67
101
  def create_command(action, klass, label, *attributes, &block)
68
102
  define_method(action) do |args, options|
69
103
  privkey = privkey_from args
@@ -187,7 +221,7 @@ class DropZoneCommand
187
221
  end
188
222
  end
189
223
 
190
- def communication_new(args, options)
224
+ def chat_new(args, options)
191
225
  network! :testnet3
192
226
 
193
227
  privkey = privkey_from args, :testnet3
@@ -207,19 +241,28 @@ class DropZoneCommand
207
241
  [:sender_addr, privkey.addr], [:receiver_addr, receiver_addr] ]
208
242
  end
209
243
 
210
- def communication_list(args, options)
244
+ def chat_list(args, options)
211
245
  network! :testnet3
212
246
 
213
247
  privkey = privkey_from args, :testnet3
214
248
 
215
- Dropzone::Session.all(privkey.addr).each do |session|
216
- puts_table '%s: %s' % ['Session', session.txid], nil, [
217
- [:sender_addr, session.sender_addr],
218
- [:receiver_addr, session.receiver_addr] ]
249
+ Dropzone::Session.all(privkey.addr).each do |init|
250
+ session = session_for privkey, init
251
+
252
+ chat_with = [init.sender_addr, init.receiver_addr].find{|a| a != privkey.addr}
253
+
254
+ chats_cache = local_persistence[:chats].first(session_txid: init.txid)
255
+ read_messages = (chats_cache) ? chats_cache[:last_read_message_count] : 0
256
+ total_messages = session.communications.length
257
+ unread_messages = (total_messages-read_messages)
258
+
259
+ puts_table '%s: %s' % ['Session', init.txid], nil, [
260
+ ['Address', chat_with],
261
+ ['Messages', '%d Unread / %d Total' % [unread_messages, total_messages ] ] ]
219
262
  end
220
263
  end
221
264
 
222
- def communication_say(args, options)
265
+ def chat_say(args, options)
223
266
  network! :testnet3
224
267
 
225
268
  privkey = privkey_from args, :testnet3
@@ -258,13 +301,13 @@ class DropZoneCommand
258
301
 
259
302
  comm_txid = session << message
260
303
 
261
- puts_table '%s: %s' % ['Communication', comm_txid], nil, [
304
+ puts_table '%s: %s' % ['Chat', comm_txid], nil, [
262
305
  ['Session', txid],
263
306
  [:sender_addr, privkey.addr],
264
307
  [:message, message] ]
265
308
  end
266
309
 
267
- def communication_show(args, options)
310
+ def chat_show(args, options)
268
311
  network! :testnet3
269
312
 
270
313
  privkey = privkey_from args, :testnet3
@@ -279,9 +322,18 @@ class DropZoneCommand
279
322
 
280
323
  session = session_for privkey, comm_init
281
324
 
282
- puts_table '%s: %s' % ['Communication', txid], nil,
283
- session.communications.collect{|comm|
325
+ update_attrs = {last_read_message_count: session.communications.length}
326
+
327
+ cache = local_persistence[:chats]
328
+ unless 1 == cache.where(session_txid: txid).update(update_attrs)
329
+ cache.insert update_attrs.merge(session_txid: txid)
330
+ end
331
+
332
+ puts_table '%s: %s' % ['Chat', txid], nil,
333
+ session.communications.reverse.collect{|comm|
284
334
  [comm.sender_addr, comm.contents_plain] }
335
+
336
+ # TODO: Determine how many messages to show here, instead of 'all'
285
337
  end
286
338
 
287
339
  def listing_find(args, options)
@@ -361,6 +413,10 @@ class DropZoneCommand
361
413
 
362
414
  private
363
415
 
416
+ def local_persistence
417
+ self.class.local_persistence
418
+ end
419
+
364
420
  def secret_for(sender_addr, receiver_addr)
365
421
  record = local_persistence[:communication_keys].where(
366
422
  Sequel.expr(receiver_addr: receiver_addr) &
@@ -378,24 +434,6 @@ class DropZoneCommand
378
434
  end
379
435
  end
380
436
 
381
- def local_persistence
382
- unless @local_persistence
383
- config_dir = File.join(Dir.home, ".dropzone")
384
- Dir.mkdir config_dir, 0700 unless Dir.exists? config_dir
385
-
386
- @local_persistence = Sequel.connect 'sqlite://%s/dropzone.db' % config_dir
387
-
388
- @local_persistence.create_table :communication_keys do
389
- primary_key :id
390
- String :sender_addr
391
- String :receiver_addr
392
- String :secret
393
- end unless @local_persistence.table_exists? :communication_keys
394
- end
395
-
396
- @local_persistence
397
- end
398
-
399
437
  def session_for(privkey, comm_init)
400
438
  receiver_addr = (comm_init.receiver_addr == privkey.addr) ?
401
439
  comm_init.sender_addr : comm_init.receiver_addr
@@ -62,12 +62,11 @@ module Dropzone
62
62
  # If we're already authenticated, we'll try to re-initialize. Presumably
63
63
  # one would want to do this if they lost a secret key, or that key were
64
64
  # somehow compromised
65
- if is_init
66
- dh = OpenSSL::PKey::DH.new(der || 1024)
67
- else
68
- raise DerAlreadyExists unless der.nil?
69
- dh = OpenSSL::PKey::DH.new with.der
70
- end
65
+ raise DerAlreadyExists unless der.nil? if !is_init
66
+
67
+ der ||= (with) ? with.der : 1024
68
+
69
+ dh = OpenSSL::PKey::DH.new der
71
70
 
72
71
  dh.priv_key = session_key
73
72
  dh.generate_key!
@@ -1,4 +1,4 @@
1
1
  module Dropzone
2
2
  # The library version string
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
@@ -16,6 +16,8 @@ describe DropZoneCommand do
16
16
  # ran before us.
17
17
  db = FakeBitcoinConnection::DB.execute(
18
18
  "UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME='transactions';" )
19
+
20
+ DropZoneCommand.local_persistence = Sequel.sqlite
19
21
  end
20
22
 
21
23
  def to_out(string)
@@ -214,7 +216,7 @@ describe DropZoneCommand do
214
216
  end
215
217
 
216
218
  it "converses" do
217
- expect{ DropZoneCommand.new(true).communication_new(
219
+ expect{ DropZoneCommand.new(true).chat_new(
218
220
  [test_privkey, TESTER2_PUBLIC_KEY], {}
219
221
  )}.to output(to_out(<<-eos)).to_stdout
220
222
  +---------------------------------------------------+
@@ -225,33 +227,33 @@ describe DropZoneCommand do
225
227
  +---------------------------------------------------+
226
228
  eos
227
229
 
228
- expect{ DropZoneCommand.new(true).communication_list(
230
+ expect{ DropZoneCommand.new(true).chat_list(
229
231
  [test_privkey], {}
230
232
  )}.to output(to_out(<<-eos)).to_stdout
231
- +---------------------------------------------------+
232
- | Session: 7 |
233
- +---------------------------------------------------+
234
- | sender_addr : mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw |
235
- | receiver_addr: mqVRfjepJTxxoDgDt892tCybhmjfKCFNyp |
236
- +---------------------------------------------------+
233
+ +----------------------------------------------+
234
+ | Session: 7 |
235
+ +----------------------------------------------+
236
+ | Address : mqVRfjepJTxxoDgDt892tCybhmjfKCFNyp |
237
+ | Messages: 0 Unread / 0 Total |
238
+ +----------------------------------------------+
237
239
  eos
238
240
 
239
- expect{ DropZoneCommand.new(true).communication_list(
241
+ expect{ DropZoneCommand.new(true).chat_list(
240
242
  [TESTER2_PRIVATE_KEY], {}
241
243
  )}.to output(to_out(<<-eos)).to_stdout
242
- +---------------------------------------------------+
243
- | Session: 7 |
244
- +---------------------------------------------------+
245
- | sender_addr : mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw |
246
- | receiver_addr: mqVRfjepJTxxoDgDt892tCybhmjfKCFNyp |
247
- +---------------------------------------------------+
244
+ +----------------------------------------------+
245
+ | Session: 7 |
246
+ +----------------------------------------------+
247
+ | Address : mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw |
248
+ | Messages: 0 Unread / 0 Total |
249
+ +----------------------------------------------+
248
250
  eos
249
251
 
250
- expect{ DropZoneCommand.new(true).communication_say(
252
+ expect{ DropZoneCommand.new(true).chat_say(
251
253
  [TESTER2_PRIVATE_KEY, '7', 'Greetings Initiator'], {}
252
254
  )}.to output(to_out(<<-eos)).to_stdout
253
255
  +-------------------------------------------------+
254
- | Communication: 9 |
256
+ | Chat: 9 |
255
257
  +-------------------------------------------------+
256
258
  | Session : 7 |
257
259
  | sender_addr: mqVRfjepJTxxoDgDt892tCybhmjfKCFNyp |
@@ -259,11 +261,11 @@ describe DropZoneCommand do
259
261
  +-------------------------------------------------+
260
262
  eos
261
263
 
262
- expect{ DropZoneCommand.new(true).communication_say(
264
+ expect{ DropZoneCommand.new(true).chat_say(
263
265
  [test_privkey, '7', 'Conversation Initiated'], {}
264
266
  )}.to output(to_out(<<-eos)).to_stdout
265
267
  +-------------------------------------------------+
266
- | Communication: 10 |
268
+ | Chat: 10 |
267
269
  +-------------------------------------------------+
268
270
  | Session : 7 |
269
271
  | sender_addr: mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw |
@@ -271,25 +273,25 @@ describe DropZoneCommand do
271
273
  +-------------------------------------------------+
272
274
  eos
273
275
 
274
- expect{ DropZoneCommand.new(true).communication_show(
276
+ expect{ DropZoneCommand.new(true).chat_show(
275
277
  [test_privkey, '7'], {}
276
278
  )}.to output(to_out(<<-eos)).to_stdout
277
279
  +------------------------------------------------------------+
278
- | Communication: 7 |
280
+ | Chat: 7 |
279
281
  +------------------------------------------------------------+
280
- | mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw: Conversation Initiated |
281
282
  | mqVRfjepJTxxoDgDt892tCybhmjfKCFNyp: Greetings Initiator |
283
+ | mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw: Conversation Initiated |
282
284
  +------------------------------------------------------------+
283
285
  eos
284
286
 
285
- expect{ DropZoneCommand.new(true).communication_show(
287
+ expect{ DropZoneCommand.new(true).chat_show(
286
288
  [TESTER2_PRIVATE_KEY, '7'], {}
287
289
  )}.to output(to_out(<<-eos)).to_stdout
288
290
  +------------------------------------------------------------+
289
- | Communication: 7 |
291
+ | Chat: 7 |
290
292
  +------------------------------------------------------------+
291
- | mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw: Conversation Initiated |
292
293
  | mqVRfjepJTxxoDgDt892tCybhmjfKCFNyp: Greetings Initiator |
294
+ | mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw: Conversation Initiated |
293
295
  +------------------------------------------------------------+
294
296
  eos
295
297
  end
@@ -315,11 +317,11 @@ is akin to that of Craigslist.org or Uber, but is distributed and as such provid
315
317
  risk-free terms to contraband sellers, and drastically reduced risk to contraband buyers.
316
318
  eos
317
319
 
318
- expect{ DropZoneCommand.new(true).communication_say(
320
+ expect{ DropZoneCommand.new(true).chat_say(
319
321
  [test_privkey, '7', abstract], {}
320
322
  )}.to output(to_out(<<-eos)).to_stdout
321
323
  +----------------------------------------------------------------------------------+
322
- | Communication: 11 |
324
+ | Chat: 11 |
323
325
  +----------------------------------------------------------------------------------+
324
326
  | Session : 7 |
325
327
  | sender_addr: mi37WkBomHJpUghCn7Vgh3ah33h6L9Nkqw |
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropzone_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miracle Max
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-31 00:00:00.000000000 Z
11
+ date: 2015-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: counterparty_ruby
@@ -177,7 +177,7 @@ extensions: []
177
177
  extra_rdoc_files: []
178
178
  files:
179
179
  - ".gitignore"
180
- - Drop Zone - An Anonymous Peer-To-Peer Local Contraband Marketplace.pdf
180
+ - Drop Zone - Whitepaper.pdf
181
181
  - Gemfile
182
182
  - Gemfile.lock
183
183
  - README.md
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  requirements: []
243
243
  rubyforge_project:
244
- rubygems_version: 2.4.6
244
+ rubygems_version: 2.4.8
245
245
  signing_key:
246
246
  specification_version: 4
247
247
  summary: An Anonymous Peer-To-Peer Local Contraband Marketplace