Skip to content

Commit

Permalink
chore(network): sync protocol, fix(cli): quote more path strings
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf committed Mar 14, 2024
1 parent dba9b82 commit 2e3b373
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions api/stream-relay/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Peer, Encryption, sha256 } from './index.js'
import { Peer, Encryption, sha256, NAT, RemotePeer } from './index.js'
import { PeerWorkerProxy } from './worker.js'
import { sodium } from '../crypto.js'
import { Buffer } from '../buffer.js'
Expand All @@ -16,6 +16,7 @@ import { Packet, CACHE_TTL } from './packets.js'
* @returns {Promise<events.EventEmitter>} - A promise that resolves to the initialized network bus.
*/
async function api (options = {}, events, dgram) {
let _peer
await sodium.ready
const bus = new events.EventEmitter()
bus._on = bus.on
Expand All @@ -37,7 +38,7 @@ async function api (options = {}, events, dgram) {
if (clusterId) clusterId = Buffer.from(clusterId) // some peers don't have clusters

const Ctor = globalThis.isSocketRuntime ? PeerWorkerProxy : Peer
const _peer = new Ctor(options, dgram)
_peer = new Ctor(options, dgram)

_peer.onJoin = (packet, ...args) => {
if (!packet.clusterId.equals(clusterId)) return
Expand Down Expand Up @@ -197,6 +198,7 @@ async function api (options = {}, events, dgram) {
const args = await pack(eventName, value, opts)
if (!options.sharedKey) {
throw new Error('Can\'t emit to the top level cluster, a shared key was not provided in the constructor or the arguments options')
return
}
return await _peer.publish(options.sharedKey || opts.sharedKey, args)
}
Expand Down
5 changes: 3 additions & 2 deletions api/stream-relay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ export class Peer {
})

return {
peers,
peers,
config: this.config,
data: [...this.cache.data.entries()],
unpublished: this.unpublished
Expand All @@ -592,6 +592,7 @@ export class Peer {
clock: this.clock,
uptime: this.uptime,
natType: this.natType,
natName: NAT.toString(this.natType),
peerId: this.peerId
}
}
Expand Down Expand Up @@ -1042,7 +1043,7 @@ export class Peer {
for (const packet of packets) {
this.cacheInsert(packet)

if (this.onPacket) this.onPacket(packet, this.port, this.address, true)
if (this.onPacket) this.onPacket(p, this.port, this.address, true)

this.unpublished[packet.packetId.toString('hex')] = Date.now()
if (globalThis.navigator && !globalThis.navigator.onLine) continue
Expand Down
3 changes: 1 addition & 2 deletions api/stream-relay/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class PeerWorkerProxy {
return await this.callWorkerThread('reconnect')
}

async disconnect () {
async reconnect () {
return await this.callWorkerThread('disconnect')
}

Expand Down Expand Up @@ -335,7 +335,6 @@ if (isWorkerThread) {
}

case 'compileCachePredicate': {
// eslint-disable-next-line
let predicate = new Function(`return ${data.toString()}`)()
predicate = predicate.bind(peer)
peer.cachePredicate = packet => predicate(packet)
Expand Down
4 changes: 2 additions & 2 deletions src/cli/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4502,7 +4502,7 @@ int main (const int argc, const char* argv[]) {
compileExtensionObjectCommand
<< "xcrun -sdk " << (flagBuildForSimulator ? "iphonesimulator" : "iphoneos")
<< " " << compiler
<< " -I" << Path(paths.platformSpecificOutputPath / "include").string()
<< " -I\"" << Path(paths.platformSpecificOutputPath / "include").string() << "\""
<< " -I" << prefixFile()
<< " -I" << prefixFile("include")
<< " -DIOS=1"
Expand Down Expand Up @@ -4580,7 +4580,7 @@ int main (const int argc, const char* argv[]) {
fs::create_directories(lib.parent_path());
compileExtensionWASMCommand
<< compiler
<< " -I" + Path(paths.platformSpecificOutputPath / "include").string()
<< " -I\"" + Path(paths.platformSpecificOutputPath / "include").string() << "\""
<< (" -I" + quote + trim(prefixFile("include")) + quote)
<< (" -I" + quote + trim(prefixFile("include/socket/webassembly")) + quote)
<< (" -I" + quote + trim(prefixFile("src")) + quote)
Expand Down

0 comments on commit 2e3b373

Please sign in to comment.