fix sender in call (#913)

This commit is contained in:
Dima 2020-06-19 14:29:06 +03:00 committed by GitHub
parent 55db70d96f
commit 8a9ad8e9de
4 changed files with 16 additions and 17 deletions

View File

@ -1,6 +1,6 @@
{
"name": "fluence",
"version": "0.5.5",
"version": "0.5.6",
"description": "the browser js-libp2p client for the Fluence network",
"main": "./dist/fluence.js",
"typings": "./dist/fluence.d.ts",

View File

@ -54,13 +54,13 @@ export class FluenceConnection {
private readonly selfPeerId: string;
private readonly handleCall: (call: FunctionCall) => FunctionCall | undefined;
constructor(multiaddr: Multiaddr, hostPeerId: PeerId, selfPeerInfo: PeerInfo, replyToAddress: Address, handleCall: (call: FunctionCall) => FunctionCall | undefined) {
constructor(multiaddr: Multiaddr, hostPeerId: PeerId, selfPeerInfo: PeerInfo, sender: Address, handleCall: (call: FunctionCall) => FunctionCall | undefined) {
this.selfPeerInfo = selfPeerInfo;
this.handleCall = handleCall;
this.selfPeerId = selfPeerInfo.id.toB58String();
this.address = multiaddr;
this.nodePeerId = hostPeerId;
this.sender = replyToAddress
this.sender = sender
}
async connect() {
@ -186,13 +186,13 @@ export class FluenceConnection {
let replyTo;
if (reply) replyTo = this.sender;
let call = makeFunctionCall(genUUID(), target, args, this.sender, replyTo, name);
let call = makeFunctionCall(genUUID(), target, this.sender, args, replyTo, name);
await this.sendCall(call);
}
async registerService(serviceId: string) {
let regMsg = await makeRegisterMessage(serviceId, this.nodePeerId, this.selfPeerInfo.id);
let regMsg = await makeRegisterMessage(serviceId, this.sender);
await this.sendCall(regMsg);
}
}
}

View File

@ -40,6 +40,7 @@ export function callToString(call: FunctionCall) {
}
obj.target = addressToString(obj.target);
obj.sender = addressToString(obj.sender);
return JSON.stringify(obj)
}
@ -102,7 +103,7 @@ export async function makeRelayCall(client: PeerId, relay: PeerId, msg: any, sen
export function makePeerCall(client: PeerId, msg: any, sender: Address, replyTo?: Address, name?: string): FunctionCall {
let peerAddress = createPeerAddress(client.toB58String());
return makeFunctionCall(genUUID(), peerAddress, msg, sender, replyTo, name);
return makeFunctionCall(genUUID(), peerAddress, sender, msg, replyTo, name);
}
/**
@ -111,17 +112,16 @@ export function makePeerCall(client: PeerId, msg: any, sender: Address, replyTo?
export function makeCall(functionId: string, args: any, sender: Address, replyTo?: Address, name?: string): FunctionCall {
let target = createServiceAddress(functionId);
return makeFunctionCall(genUUID(), target, args, sender, replyTo, name);
return makeFunctionCall(genUUID(), target, sender, args, replyTo, name);
}
/**
* Message to register new service_id.
*/
export async function makeRegisterMessage(serviceId: string, relayPeerId: PeerId, selfPeerId: PeerId): Promise<FunctionCall> {
export async function makeRegisterMessage(serviceId: string, sender: Address): Promise<FunctionCall> {
let target = createServiceAddress("provide");
let replyTo = await createRelayAddress(relayPeerId.toB58String(), selfPeerId, true);
return makeFunctionCall(genUUID(), target, replyTo, {service_id: serviceId}, replyTo, "provide service_id");
return makeFunctionCall(genUUID(), target, sender, {service_id: serviceId}, sender, "provide service_id");
}
// TODO uncomment when this will be implemented in Fluence network

View File

@ -55,7 +55,6 @@ describe("Typescript usage suite", () => {
let relayid = await PeerId.create();
let addr = await createRelayAddress(relayid.toB58String(), pid, true);
let pid2 = await PeerId.create();
let addr2 = createPeerAddress(pid.toB58String());
let functionCall = makeFunctionCall(
@ -137,8 +136,8 @@ export async function testCerts() {
let key2 = await Fluence.generatePeerId();
// connect to two different nodes
let cl1 = await Fluence.connect("/dns4/104.248.25.59/tcp/9003/ws/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb", key1);
let cl2 = await Fluence.connect("/ip4/104.248.25.59/tcp/9002/ws/p2p/12D3KooWHk9BjDQBUqnavciRPhAYFvqKBe4ZiPPvde7vDaqgn5er", key2);
let cl1 = await Fluence.connect("/dns4/134.209.186.43/tcp/9003/ws/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb", key1);
let cl2 = await Fluence.connect("/ip4/134.209.186.43/tcp/9002/ws/p2p/12D3KooWHk9BjDQBUqnavciRPhAYFvqKBe4ZiPPvde7vDaqgn5er", key2);
let trustGraph1 = new TrustGraph(cl1);
let trustGraph2 = new TrustGraph(cl2);
@ -172,8 +171,8 @@ export async function testCalculator() {
let key2 = await Fluence.generatePeerId();
// connect to two different nodes
let cl1 = await Fluence.connect("/dns4/104.248.25.59/tcp/9003/ws/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb", key1);
let cl2 = await Fluence.connect("/ip4/104.248.25.59/tcp/9002/ws/p2p/12D3KooWHk9BjDQBUqnavciRPhAYFvqKBe4ZiPPvde7vDaqgn5er", key2);
let cl1 = await Fluence.connect("/dns4/134.209.186.43/tcp/9003/ws/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb", key1);
let cl2 = await Fluence.connect("/ip4/134.209.186.43/tcp/9002/ws/p2p/12D3KooWHk9BjDQBUqnavciRPhAYFvqKBe4ZiPPvde7vDaqgn5er", key2);
// service name that we will register with one connection and call with another
let serviceId = "sum-calculator-" + genUUID();
@ -205,7 +204,7 @@ export async function testCalculator() {
let result = response.result;
console.log(`calculation result is: ${result}`);
await cl1.connect("/dns4/relay01.fluence.dev/tcp/19001/wss/p2p/12D3KooWEXNUbCXooUwHrHBbrmjsrpHXoEphPwbjQXEGyzbqKnE9");
await cl1.connect("/dns4/relay02.fluence.dev/tcp/19001/wss/p2p/12D3KooWEXNUbCXooUwHrHBbrmjsrpHXoEphPwbjQXEGyzbqKnE9");
await delay(1000);