Add Pigeon::Helpers.lipmaa in preparation for lipmaa backlinking

This commit is contained in:
Netscape Navigator 2020-04-11 09:46:40 -05:00
parent c82eb7a3c9
commit 71a93e91e7
2 changed files with 25 additions and 3 deletions

View File

@ -53,11 +53,11 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`.
- [X] Message.ingest should be the only code path to message authoring.
- [X] Don't allow any type of whitespace in `kind` or `string` keys. Write a test for this.
- [X] Run Flog / Flay and friends to find duplications. Will aid in port to other languages.
- [ ] Make all methods private except those required for the CLI.
- [ ] Make CLI names consistent with API names. Eg: find vs. read.
- [X] Make all methods private except those required for the CLI.
- [ ] Add Lipmaa links like the Bamboo folks do.
- [ ] Create regexes in ::Lexer using strings and Regexp.new() for cleaner regexes.
- [ ] 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.
- [ ] Create regexes in ::Lexer using strings and Regexp.new() for cleaner regexes.
- [ ] 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)
- [ ] Add mandatory `--since=` arg to `bundle create`

22
dist/pigeon.rb vendored
View File

@ -83,6 +83,28 @@ module Pigeon
"X" => 0b11101, "Y" => 0b11110, "Z" => 0b11111,
}.freeze
def self.lipmaa(n)
m, po3, x = 1, 3, n
# find k such that (3^k - 1)/2 >= n
while (m < n)
po3 *= 3
m = (po3 - 1) / 2
end
po3 /= 3
# find longest possible backjump
if (m != n)
while x != 0
m = (po3 - 1) / 2
po3 /= 3
x %= m
end
if (m != po3)
po3 = m
end
end
return n - po3
end
# http://www.crockford.com/wrmg/base32.html
def self.b32_encode(string)
string