TODO: Fix directory structure of exported bundles.
This commit is contained in:
parent
589b683a12
commit
7edf4db041
|
@ -5,4 +5,5 @@ doc/
|
|||
*scratchpad*
|
||||
pigeon.bundle
|
||||
*.gem
|
||||
bundle/
|
||||
bundle/
|
||||
pigeon.db
|
79
TODO.md
79
TODO.md
|
@ -1,79 +0,0 @@
|
|||
I need to implement these.
|
||||
|
||||
I'm adding them here for quick reference.
|
||||
|
||||
```
|
||||
author @ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519
|
||||
sequence 23
|
||||
kind "example"
|
||||
previous %85738f8f9a7f1b04b5329c590ebcb9e425925c6d0984089c43a022de4f19c281.sha256
|
||||
timestamp 23123123123
|
||||
|
||||
"foo":&3f79bb7b435b05321651daefd374cdc681dc06faa65e374e38337b88ca046dea.sha256
|
||||
"baz":"bar"
|
||||
"my_friend":@abcdef1234567890.ed25519
|
||||
"really_cool_message":%85738f8f9a7f1b04b5329c590ebcb9e425925c6d0984089c43a022de4f19c281.sha256
|
||||
"baz":"whatever"
|
||||
|
||||
signature "3er8...LOgRdrGnuihBp4QYWYPJ5bS1Gw9weQKj9DQ==.sig.ed25519"
|
||||
```
|
||||
|
||||
```bash
|
||||
pigeon message new my_message
|
||||
# => "Switched to message (kind: `my_message`)
|
||||
|
||||
pigeon message current # Show active log entry.
|
||||
# => author: @ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519
|
||||
|
||||
pigeon message append --name=2e7a0bc3 --value=2e7a0bc3
|
||||
# => \n
|
||||
# => This needs to be cleaner.
|
||||
# => No one likes the way it is right now.
|
||||
# => We will come back to this monstrosity later.
|
||||
|
||||
pigeon message sign
|
||||
# => author: @ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519
|
||||
# => depth: 1
|
||||
# => kind: &82244417f956ac7c599f191593f7e441a4fafa20a4158fd52e154f1dc4c8ed92.sha256
|
||||
# => prev: %jvKh9yoiEJaePzoWCF1nnqpIlPgTk9FHEtqczQbvzGM=.sha256
|
||||
# =>
|
||||
# => &ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb.sha256:&2e7a0bc31f3c4fe6114051c3a56c8ed8a030b3b394df7d29d37648e9b8cbf54b.sha256
|
||||
# =>
|
||||
|
||||
pigeon message find %g0Fs9yoiEJaePzoWCF1nnqpIlPgTk9FHEtqczQbvzGM=.sha256
|
||||
# => author: @ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519
|
||||
# => depth: 1
|
||||
# => kind: &82244417f956ac7c599f191593f7e441a4fafa20a4158fd52e154f1dc4c8ed92.sha256
|
||||
# => prev: %jvKh9yoiEJaePzoWCF1nnqpIlPgTk9FHEtqczQbvzGM=.sha256
|
||||
# =>
|
||||
# => &ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb.sha256:&2e7a0bc31f3c4fe6114051c3a56c8ed8a030b3b394df7d29d37648e9b8cbf54b.sha256
|
||||
# =>
|
||||
|
||||
pigeon message find-all --author=@ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519 --since=1
|
||||
# => author: @ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519
|
||||
# => depth: 1
|
||||
# => kind: &82244417f956ac7c599f191593f7e441a4fafa20a4158fd52e154f1dc4c8ed92.sha256
|
||||
# => prev: %jvKh9yoiEJaePzoWCF1nnqpIlPgTk9FHEtqczQbvzGM=.sha256
|
||||
# =>
|
||||
# => &ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb.sha256:&2e7a0bc31f3c4fe6114051c3a56c8ed8a030b3b394df7d29d37648e9b8cbf54b.sha256
|
||||
# =>
|
||||
# => author: @ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519
|
||||
# => depth: 2
|
||||
# => kind: &82244417f956ac7c599f191593f7e441a4fafa20a4158fd52e154f1dc4c8ed92.sha256
|
||||
# => prev: %jvKh9yoiEJaePzoWCF1nnqpIlPgTk9FHEtqczQbvzGM=.sha256
|
||||
# =>
|
||||
# => &ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb.sha256:&2e7a0bc31f3c4fe6114051c3a56c8ed8a030b3b394df7d29d37648e9b8cbf54b.sha256
|
||||
# =>
|
||||
|
||||
pigeon peer all
|
||||
# => @c8hovH5OOzNJ1SXUsIN+zI23xMcvGdEbs3ZJgzpthrw=.ed25519
|
||||
# => @GOl+398b2kWeLi6+DCcU0i3AWD6vWmUtocBVYbpkpNk=.ed25519
|
||||
# => @m0LEP+0NrGqu1wT8/4a3nOPuRBM+DrMpUahDZ3/cDi8=.ed25519
|
||||
|
||||
pigeon bundle create
|
||||
# => (creates @GOl+398b2kWeLi6+DCcU0i3AWD6vWmUtocBVYbpkpNk=.ed25519.pgn)
|
||||
|
||||
pigeon bundle consume @GOl+398b2kWeLi6+DCcU0i3AWD6vWmUtocBVYbpkpNk=.ed25519.pgn
|
||||
# =>
|
||||
|
||||
```
|
|
@ -2,6 +2,7 @@ require "digest"
|
|||
require "ed25519"
|
||||
require "securerandom"
|
||||
require "set"
|
||||
require "fileutils"
|
||||
|
||||
module Pigeon
|
||||
SEED_CONFIG_KEY = "SEED"
|
||||
|
@ -207,7 +208,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def self.mkdir_p(path)
|
||||
Dir.mkdir(path) unless Dir.exists?(path)
|
||||
FileUtils.makedirs(path) unless Dir.exists?(path)
|
||||
end
|
||||
|
||||
def self.write_to_disk(base_path, mhash, data)
|
||||
|
@ -226,7 +227,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def self.hash2file_path(mhash)
|
||||
mhash = mhash.sub("&", "")
|
||||
mhash = mhash.sub(BLOB_SIGIL, "")
|
||||
|
||||
[
|
||||
mhash[0...7],
|
||||
|
@ -246,6 +247,12 @@ module Pigeon
|
|||
return b32_decode(string[1..].gsub(FOOTERS_REGEX, ""))
|
||||
end
|
||||
end
|
||||
|
||||
def self.blob_multihash?(unknown)
|
||||
(unknown.is_a?(String) &&
|
||||
unknown.length == 60 &&
|
||||
(unknown[0] == BLOB_SIGIL))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -94,6 +94,8 @@ module Pigeon
|
|||
|
||||
# === BUNDLES
|
||||
def export_bundle(file_path = DEFAULT_BUNDLE_PATH)
|
||||
Helpers.mkdir_p(file_path)
|
||||
|
||||
# Fetch messages for all peers
|
||||
peers = all_peers + [who_am_i.multihash]
|
||||
messages = peers.map do |peer|
|
||||
|
@ -107,20 +109,32 @@ module Pigeon
|
|||
.map(&:collect_blobs)
|
||||
.flatten
|
||||
.uniq
|
||||
.map { |mhash| ["bundle", mhash, get_blob(mhash)] }
|
||||
.map { |arg| Helpers.write_to_disk(*arg) }
|
||||
.map do |mhash|
|
||||
blob_path = File.join(file_path, Helpers.hash2file_path(mhash))
|
||||
Helpers.write_to_disk(blob_path, mhash, get_blob(mhash))
|
||||
end
|
||||
|
||||
# Render messages for all peers.
|
||||
content = messages
|
||||
.map { |message| message.render }
|
||||
.join(BUNDLE_MESSAGE_SEPARATOR)
|
||||
File.join(file_path, "gossip.pgn")
|
||||
|
||||
File.write(File.join(file_path, "gossip.pgn"), content + CR)
|
||||
end
|
||||
|
||||
def import_bundle(file_path = DEFAULT_BUNDLE_PATH)
|
||||
bundle = File.read(File.join(file_path, "gossip.pgn"))
|
||||
tokens = Pigeon::Lexer.tokenize(bundle)
|
||||
blobs = tokens.reduce(Set.new) do |set, (a, b, c)|
|
||||
[b, c].map do |d|
|
||||
set.add(d) if Helpers.blob_multihash?(d)
|
||||
end
|
||||
set
|
||||
end.map do |multihash|
|
||||
if !store.have_blob?(multihash)
|
||||
binding.pry
|
||||
end
|
||||
end
|
||||
Pigeon::Parser.parse(self, tokens)
|
||||
end
|
||||
|
||||
|
|
|
@ -130,6 +130,11 @@ module Pigeon
|
|||
read { store[BLCK_NS].member?(multihash) }
|
||||
end
|
||||
|
||||
def have_blob?(multihash)
|
||||
path = File.join(PIGEON_BLOB_PATH, Helpers.hash2file_path(multihash))
|
||||
File.file?(path)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def write_to_disk(mhash, data)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
c.gif
|
|
@ -0,0 +1 @@
|
|||
a.gif
|
|
@ -0,0 +1 @@
|
|||
b.gif
|
|
@ -47,6 +47,12 @@ RSpec.describe Pigeon::Message do
|
|||
|
||||
it "ingests a bundle's blobs" do
|
||||
db.reset_database
|
||||
db.add_message(db.add_blob("a.gif"), {
|
||||
db.add_blob("b.gif") => db.add_blob("c.gif"),
|
||||
})
|
||||
db.export_bundle("./spec/fixtures/has_blobs")
|
||||
STDERR.puts("The directory structure is not correct.")
|
||||
exit(1)
|
||||
db.import_bundle("./spec/fixtures/has_blobs")
|
||||
expect(db.all_messages.count).to eq(0)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue