-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:coasys/ad4m into dev
- Loading branch information
Showing
17 changed files
with
85 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ import { LinkSyncAdapter, PerspectiveDiffObserver, HolochainLanguageDelegate, La | |
import type { SyncStateChangeObserver } from "https://esm.sh/@perspect3vism/[email protected]"; | ||
import { Mutex, withTimeout } from "https://esm.sh/[email protected]"; | ||
import { DNA_NICK, ZOME_NAME } from "./build/dna.js"; | ||
import { encodeBase64 } from "https://deno.land/[email protected]/encoding/base64.ts"; | ||
|
||
class PeerInfo { | ||
//@ts-ignore | ||
currentRevision: Buffer; | ||
currentRevision: Uint8Array; | ||
//@ts-ignore | ||
lastSeen: Date; | ||
}; | ||
|
@@ -19,7 +20,7 @@ export class LinkAdapter implements LinkSyncAdapter { | |
generalMutex: Mutex = withTimeout(new Mutex(), 10000, new Error('PerspectiveDiffSync: generalMutex timeout')); | ||
me: DID | ||
gossipLogCount: number = 0; | ||
myCurrentRevision: Buffer | null = null; | ||
myCurrentRevision: Uint8Array | null = null; | ||
|
||
constructor(context: LanguageContext) { | ||
//@ts-ignore | ||
|
@@ -56,8 +57,7 @@ export class LinkAdapter implements LinkSyncAdapter { | |
try { | ||
//@ts-ignore | ||
let current_revision = await this.hcDna.call(DNA_NICK, ZOME_NAME, "sync", null); | ||
console.log("PerspectiveDiffSync.sync(); current_revision", current_revision); | ||
if (current_revision && Buffer.isBuffer(current_revision)) { | ||
if (current_revision && current_revision instanceof Uint8Array) { | ||
this.myCurrentRevision = current_revision; | ||
} | ||
} catch (e) { | ||
|
@@ -90,13 +90,13 @@ export class LinkAdapter implements LinkSyncAdapter { | |
peers.push(this.me); | ||
|
||
// Lexically sort the peers | ||
peers.sort(); | ||
peers = peers.sort(); | ||
|
||
// If we are the first peer, we are the scribe | ||
let is_scribe = peers[0] == this.me; | ||
let is_scribe = (peers[0] == this.me); | ||
|
||
// Get a deduped set of all peer's current revisions | ||
let revisions = new Set<Buffer>(); | ||
let revisions = new Set<Uint8Array>(); | ||
for(const peerInfo of this.peers.values()) { | ||
if (peerInfo.currentRevision) revisions.add(peerInfo.currentRevision); | ||
} | ||
|
@@ -107,15 +107,15 @@ export class LinkAdapter implements LinkSyncAdapter { | |
//Get a copied array of revisions that are different than mine | ||
let differentRevisions; | ||
|
||
function generateRevisionStates(myCurrentRevision: Buffer) { | ||
function generateRevisionStates(myCurrentRevision: Uint8Array) { | ||
sameRevisions = revisions.size == 0 ? [] : Array.from(revisions).filter( (revision) => { | ||
return myCurrentRevision && revision.equals(myCurrentRevision); | ||
return myCurrentRevision && (encodeBase64(revision) == encodeBase64(myCurrentRevision)); | ||
}); | ||
if (myCurrentRevision) { | ||
sameRevisions.push(myCurrentRevision); | ||
}; | ||
differentRevisions = revisions.size == 0 ? [] : Array.from(revisions).filter( (revision) => { | ||
return myCurrentRevision && !revision.equals(myCurrentRevision); | ||
return myCurrentRevision && !(encodeBase64(revision) == encodeBase64(myCurrentRevision)); | ||
}); | ||
} | ||
|
||
|
@@ -137,11 +137,13 @@ export class LinkAdapter implements LinkSyncAdapter { | |
|
||
for (const hash of Array.from(revisions)) { | ||
if(!hash) continue | ||
if (this.myCurrentRevision && hash.equals(this.myCurrentRevision)) continue | ||
if (this.myCurrentRevision && (encodeBase64(hash) == encodeBase64(this.myCurrentRevision))) continue; | ||
|
||
let pullResult = await this.hcDna.call(DNA_NICK, ZOME_NAME, "pull", { | ||
hash, | ||
is_scribe | ||
}); | ||
|
||
if (pullResult) { | ||
if (pullResult.current_revision && Buffer.isBuffer(pullResult.current_revision)) { | ||
let myRevision = pullResult.current_revision; | ||
|
@@ -169,12 +171,12 @@ export class LinkAdapter implements LinkSyncAdapter { | |
-- | ||
${Array.from(this.peers.entries()).map( ([peer, peerInfo]) => { | ||
//@ts-ignore | ||
return `${peer}: ${peerInfo.currentRevision.toString('base64')} ${peerInfo.lastSeen.toISOString()}\n` | ||
return `${peer}: ${encodeBase64(peerInfo.currentRevision)} ${peerInfo.lastSeen.toISOString()}\n` | ||
})} | ||
-- | ||
revisions: ${Array.from(revisions).map( (hash) => { | ||
//@ts-ignore | ||
return hash.toString('base64') | ||
return encodeBase64(hash) | ||
})} | ||
`); | ||
this.gossipLogCount = 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters