Fix a bunch of bugs that came up only now that we are dealing with remote peers

This commit is contained in:
Netscape Navigator 2020-03-26 08:17:50 -05:00
parent 8d2a721d84
commit 2805bdf78c
6 changed files with 26 additions and 9 deletions

1
dist/pigeon.rb vendored
View File

@ -55,6 +55,7 @@ module Pigeon
end
require_relative File.join("pigeon", "local_identity.rb")
require_relative File.join("pigeon", "remote_identity.rb")
require_relative File.join("pigeon", "storage.rb")
require_relative File.join("pigeon", "draft_serializer.rb")
require_relative File.join("pigeon", "message_serializer.rb")

View File

@ -6,7 +6,7 @@ module Pigeon
author = Pigeon::LocalIdentity.current
range = (0...last).to_a
content = range
.map { |depth| s.get_message_by_depth(author, depth) }
.map { |depth| s.get_message_by_depth(author.public_key, depth) }
.map { |multihash| s.find_message(multihash) }
.map { |message| message.render }
.join(BUNDLE_MESSAGE_SEPARATOR)

View File

@ -19,7 +19,7 @@ module Pigeon
# Store a message that someone (not the LocalIdentity)
# has authored.
def self.ingest(author:, body:, depth:, kind:, prev:, signature:)
message = new(author: author,
message = new(author: RemoteIdentity.new(author),
kind: kind,
body: body,
signature: signature)
@ -57,13 +57,13 @@ module Pigeon
store = Pigeon::Storage.current
@depth = store.message_count
@signature = signature || calculate_signature
@prev = store.get_message_by_depth(@author, @depth - 1)
@prev = store.get_message_by_depth(@author.public_key, @depth - 1)
self.freeze
store.save_message(self)
end
def template
@template ||= MessageSerializer.new(self)
MessageSerializer.new(self)
end
def calculate_signature

16
dist/pigeon/remote_identity.rb vendored Normal file
View File

@ -0,0 +1,16 @@
module Pigeon
# A private key pair that represents a
# user who "owns" the database.
#
# Provides a wrapper around the `ed25519` gem to
# help us maintain our sanity when the Gem's API
# changes.
class RemoteIdentity
attr_reader :public_key
def initialize(multihash)
b64 = Base64.urlsafe_encode64(multihash)
@public_key = [HEADER, b64, FOOTER].join("")
end
end
end

View File

@ -11,11 +11,11 @@ module Pigeon
@current ||= self.new
end
def get_message_by_depth(author, depth)
raise "Expected string, got #{author.class}" unless author.is_a?(String) # Delete later
def get_message_by_depth(multihash, depth)
raise "Expected string, got #{multihash.class}" unless multihash.is_a?(String) # Delete later
store.transaction do
# Map<[author(str), depth(int)], Signature>
store[DEPTH_INDEX_NS][[author, depth]]
# Map<[multihash(str), depth(int)], Signature>
store[DEPTH_INDEX_NS][[multihash, depth]]
end
end

View File

@ -148,7 +148,7 @@ module Pigeon
def last
me = Pigeon::LocalIdentity.current
store = Pigeon::Storage.current
multihash = store.get_message_by_depth(me, store.message_count - 1)
multihash = store.get_message_by_depth(me.public_key, store.message_count - 1)
puts multihash
end
end