Begin renaming database methods for consistency

This commit is contained in:
Netscape Navigator 2020-04-19 09:25:42 -05:00
parent fc580010f9
commit 638ce7c9b0
12 changed files with 51 additions and 23 deletions

View File

@ -76,9 +76,12 @@ TODO
- [X] Clean up all singletons / .current hacks
- [X] Reduce cross cutting where collaborating objects need access to `@db`
- [X] Ensure all disks writes perform verification!
- [ ] Make CLI names consistent with API names. Eg: find vs. read.
- [ ] Add log count to `pigeon-cli status`
- [ ] Name bundles after their hash?
- [ ] `find-all` should....find all. Currently finds all for your messages.
- [ ] Update README.md. Needs user manual for new `Pigeon::Database` class.
- [ ] Make the switch to LevelDB, RocksDB, [UNQLite](https://unqlite.org/features.html) or similar (currently using Ruby PStore).
- [ ] Make CLI names consistent with API names. Eg: find vs. read.
- [ ] Need a way of importing / exporting a feeds blobs. (see "Bundle Brainstorming" below)
- [ ] Need a way of adding peers messages / gossip to bundles. (see "Bundle Brainstorming" below)
- [ ] Check block list before ingesting bundles.

View File

@ -152,7 +152,7 @@ module Pigeon
desc "find-all", "Find a pigeon message in the local DB"
def find_all(author = db.local_identity.multihash)
puts db.find_all(author).join(Pigeon::CR) + Pigeon::CR
puts db.find_all_messages(author).join(Pigeon::CR) + Pigeon::CR
end
desc "last", "Grab your last message. INTERNAL USE ONLY"

View File

@ -11,7 +11,7 @@ module Pigeon
def all_blocks(); store.all_blocks(); end
def all_peers(); store.all_peers(); end
def block_peer(p); store.block_peer(p); end
def find_all(mhash); store.find_all(mhash); end
def find_all_messages(mhash); store.find_all_messages(mhash); end
def get_blob(b); store.get_blob(b); end
def get_config(k); store.get_config(k); end
def message?(multihash); store.message?(multihash); end
@ -19,11 +19,7 @@ module Pigeon
def remove_peer(p); store.remove_peer(p); end
def reset_current_draft; set_config(CURRENT_DRAFT, nil); end
def set_config(k, v); store.set_config(k, v); end
def reset
store.reset
init_ident
end
def reset_database; store.reset; init_ident; end
def save_message(msg_obj)
store.insert_message(Helpers.verify_message(self, msg_obj))
@ -47,7 +43,7 @@ module Pigeon
def create_bundle(file_path = DEFAULT_BUNDLE_PATH)
content = store
.find_all(local_identity.multihash)
.find_all_messages(local_identity.multihash)
.map { |multihash| store.read_message(multihash) }
.sort_by(&:depth)
.map { |message| message.render }
@ -86,7 +82,7 @@ module Pigeon
# Store a message that someone (not the LocalIdentity)
# has authored.
def ingest(author:, body:, depth:, kind:, lipmaa:, prev:, signature:)
def ingest_message(author:, body:, depth:, kind:, lipmaa:, prev:, signature:)
msg = Message.new(author: RemoteIdentity.new(author),
kind: kind,
body: body,

View File

@ -40,7 +40,7 @@ module Pigeon
def finish_this_message!
@scratchpad.freeze
@results.push(@db.ingest(**@scratchpad))
@results.push(@db.ingest_message(**@scratchpad))
reset_scratchpad
end

View File

@ -74,7 +74,7 @@ module Pigeon
read { store[COUNT_INDEX_NS][mhash] || 0 }
end
def find_all(author)
def find_all_messages(author)
all = []
depth = -1
last = ""

View File

@ -8,7 +8,7 @@ RSpec.describe Pigeon::Message do
let(:db) do
db = Pigeon::Database.new
db.reset
db.reset_database
db
end

View File

@ -3,7 +3,7 @@ require "spec_helper"
RSpec.describe Pigeon::Draft do
let(:db) do
db = Pigeon::Database.new
db.reset
db.reset_database
db
end
@ -15,8 +15,6 @@ RSpec.describe Pigeon::Draft do
message
end
before(:each) { db.reset }
MSG = [
"author DRAFT",
"kind unit_test",

View File

@ -117,7 +117,7 @@ RSpec.describe Pigeon::Lexer do
let(:db) do
db = Pigeon::Database.new
db.reset
db.reset_database
db
end

View File

@ -14,7 +14,7 @@ RSpec.describe Pigeon::Message do
let(:db) do
db = Pigeon::Database.new
db.reset
db.reset_database
db
end
@ -105,6 +105,7 @@ RSpec.describe Pigeon::Message do
end
it "verifies accuracy of signatures" do
print "?SLOW?"
# === Initial setup
secret = db.get_config(Pigeon::SEED_CONFIG_KEY)
expect(secret).to be_kind_of(String)

View File

@ -3,7 +3,7 @@ require "spec_helper"
RSpec.describe Pigeon::Lexer do
let(:db) do
db = Pigeon::Database.new
db.reset
db.reset_database
db
end
let(:example_bundle) { File.read("./spec/fixtures/normal.bundle") }

View File

@ -7,7 +7,7 @@ RSpec.describe Pigeon::Storage do
let(:db) do
db = Pigeon::Database.new
db.reset
db.reset_database
db
end
@ -50,8 +50,8 @@ RSpec.describe Pigeon::Storage do
it "finds all authored by a particular feed" do
ingested_messages = db.ingest_bundle("./spec/fixtures/normal.bundle")
author = ingested_messages.first.author.multihash
actual_messages = db.find_all(author)
search_results = db.find_all(author)
actual_messages = db.find_all_messages(author)
search_results = db.find_all_messages(author)
end
it "finds all messages" do
@ -68,7 +68,7 @@ RSpec.describe Pigeon::Storage do
}),
]
me = db.local_identity.multihash
results = db.find_all(me)
results = db.find_all_messages(me)
expect(results.length).to eq(3)
expect(msgs[0].multihash).to eq(results[0])
expect(msgs[1].multihash).to eq(results[1])

30
x.bundle Normal file
View File

@ -0,0 +1,30 @@
author @PPJQ3Q36W258VQ1NKYY2G7VW24J8NMAACHXCD83GCQ3K8F4C9X2G.ed25519
kind carlinoType
prev NONE
depth 0
lipmaa 0
author:"daniel"
company:"Dev Man Dan LLC"
signature 2H7WM4F53YDJ2CR6XMTM6S7HSDMHD5K4Y9A2DYXWDDSRBZB1KN092FC6H69RB79VQVZ769NY5VRT7FXJVN2B2DJ163H5ZWSYV3WVY2G.sig.ed25519
author @PPJQ3Q36W258VQ1NKYY2G7VW24J8NMAACHXCD83GCQ3K8F4C9X2G.ed25519
kind MESSAGE_TYPE_HERE
prev %N4QCWKV4ERKKV5BHBYAQK0AX1VQDAMFX972SK1E4BR3HDHXMFPVG.sha256
depth 1
lipmaa 0
my_key:"my_value"
signature JD8HGEMTQKCNV7RM488VAV1XC54W4MT2Y0G4N2VME4G4QFXT2H670M3YMY4W6E1R3MTGJBADGYGW2DJPT14R9TWM87SMNNNZ6Q2NE00.sig.ed25519
author @PPJQ3Q36W258VQ1NKYY2G7VW24J8NMAACHXCD83GCQ3K8F4C9X2G.ed25519
kind theSlowestWayToSendAMessageEver
prev %K2EKKRFA5F34VG9JSW17SS5HNQAKZTTNP6A9DVR2ZBPG8GME3QVG.sha256
depth 2
lipmaa 1
yo_dawg:"i heard you like gossip protocols"
signature QM8ERCNP4NM4Y3PY09EWVCWJ6MJKPRN67EX4P8MN6DE47BZSG4M3XXCT3JWVRR7D0232Z5HYCQ5J8744JNFBYXFN8JGXM0R0ZESSR2R.sig.ed25519