TODO: Fix directory structure of exported bundles.
This commit is contained in:
parent
589b683a12
commit
7edf4db041
|
@ -5,4 +5,5 @@ doc/
|
||||||
*scratchpad*
|
*scratchpad*
|
||||||
pigeon.bundle
|
pigeon.bundle
|
||||||
*.gem
|
*.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 "ed25519"
|
||||||
require "securerandom"
|
require "securerandom"
|
||||||
require "set"
|
require "set"
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
module Pigeon
|
module Pigeon
|
||||||
SEED_CONFIG_KEY = "SEED"
|
SEED_CONFIG_KEY = "SEED"
|
||||||
|
@ -207,7 +208,7 @@ module Pigeon
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.mkdir_p(path)
|
def self.mkdir_p(path)
|
||||||
Dir.mkdir(path) unless Dir.exists?(path)
|
FileUtils.makedirs(path) unless Dir.exists?(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.write_to_disk(base_path, mhash, data)
|
def self.write_to_disk(base_path, mhash, data)
|
||||||
|
@ -226,7 +227,7 @@ module Pigeon
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hash2file_path(mhash)
|
def self.hash2file_path(mhash)
|
||||||
mhash = mhash.sub("&", "")
|
mhash = mhash.sub(BLOB_SIGIL, "")
|
||||||
|
|
||||||
[
|
[
|
||||||
mhash[0...7],
|
mhash[0...7],
|
||||||
|
@ -246,6 +247,12 @@ module Pigeon
|
||||||
return b32_decode(string[1..].gsub(FOOTERS_REGEX, ""))
|
return b32_decode(string[1..].gsub(FOOTERS_REGEX, ""))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.blob_multihash?(unknown)
|
||||||
|
(unknown.is_a?(String) &&
|
||||||
|
unknown.length == 60 &&
|
||||||
|
(unknown[0] == BLOB_SIGIL))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,8 @@ module Pigeon
|
||||||
|
|
||||||
# === BUNDLES
|
# === BUNDLES
|
||||||
def export_bundle(file_path = DEFAULT_BUNDLE_PATH)
|
def export_bundle(file_path = DEFAULT_BUNDLE_PATH)
|
||||||
|
Helpers.mkdir_p(file_path)
|
||||||
|
|
||||||
# Fetch messages for all peers
|
# Fetch messages for all peers
|
||||||
peers = all_peers + [who_am_i.multihash]
|
peers = all_peers + [who_am_i.multihash]
|
||||||
messages = peers.map do |peer|
|
messages = peers.map do |peer|
|
||||||
|
@ -107,20 +109,32 @@ module Pigeon
|
||||||
.map(&:collect_blobs)
|
.map(&:collect_blobs)
|
||||||
.flatten
|
.flatten
|
||||||
.uniq
|
.uniq
|
||||||
.map { |mhash| ["bundle", mhash, get_blob(mhash)] }
|
.map do |mhash|
|
||||||
.map { |arg| Helpers.write_to_disk(*arg) }
|
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.
|
# Render messages for all peers.
|
||||||
content = messages
|
content = messages
|
||||||
.map { |message| message.render }
|
.map { |message| message.render }
|
||||||
.join(BUNDLE_MESSAGE_SEPARATOR)
|
.join(BUNDLE_MESSAGE_SEPARATOR)
|
||||||
File.join(file_path, "gossip.pgn")
|
|
||||||
File.write(File.join(file_path, "gossip.pgn"), content + CR)
|
File.write(File.join(file_path, "gossip.pgn"), content + CR)
|
||||||
end
|
end
|
||||||
|
|
||||||
def import_bundle(file_path = DEFAULT_BUNDLE_PATH)
|
def import_bundle(file_path = DEFAULT_BUNDLE_PATH)
|
||||||
bundle = File.read(File.join(file_path, "gossip.pgn"))
|
bundle = File.read(File.join(file_path, "gossip.pgn"))
|
||||||
tokens = Pigeon::Lexer.tokenize(bundle)
|
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)
|
Pigeon::Parser.parse(self, tokens)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,11 @@ module Pigeon
|
||||||
read { store[BLCK_NS].member?(multihash) }
|
read { store[BLCK_NS].member?(multihash) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def have_blob?(multihash)
|
||||||
|
path = File.join(PIGEON_BLOB_PATH, Helpers.hash2file_path(multihash))
|
||||||
|
File.file?(path)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def write_to_disk(mhash, data)
|
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
|
it "ingests a bundle's blobs" do
|
||||||
db.reset_database
|
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")
|
db.import_bundle("./spec/fixtures/has_blobs")
|
||||||
expect(db.all_messages.count).to eq(0)
|
expect(db.all_messages.count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue