Skip to content

Commit

Permalink
fix(satp-hermes): fix handler and service intialization
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Belchior <[email protected]>
  • Loading branch information
RafaelAPB committed Aug 14, 2024
1 parent 6f98031 commit 7da3f27
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export class SATPError extends Error {
export class SATPInternalError extends Error {
constructor(
message: string,
public message: string,
// TODO internal error codes
public code: number = 500,
public internalErrorId?: string,
public traceID?: string,
public trace?: string,
) {
super(message);
Expand All @@ -12,35 +13,37 @@ export class SATPError extends Error {
}
}

export class BootstrapError extends SATPError {
constructor(internalErrorId?: string, trace?: string) {
export class BootstrapError extends SATPInternalError {
constructor(traceID?: string, trace?: string) {
super(
"Bootstrap already called in this Gateway Manager",
409,
internalErrorId,
traceID,
trace,
);
}
}

export class NonExistantGatewayIdentity extends SATPError {
constructor(id: string, internalErrorId?: string, trace?: string) {
super(`Gateway with id ${id} does not exist`, 404, internalErrorId, trace);
export class NonExistantGatewayIdentity extends SATPInternalError {
constructor(id: string, traceID?: string, trace?: string) {
super(`Gateway with id ${id} does not exist`, 404, traceID, trace);
}
}

export class GetStatusError extends SATPError {
export class GetStatusError extends SATPInternalError {
constructor(
sessionID: string,
message: string,
internalErrorId?: string,
traceID?: string,
trace?: string,
) {
super(
`Could not GetStatus at Session: with id ${sessionID}. Reason: ${message}`,
400,
internalErrorId,
traceID,
trace,
);
}
}
// TODO client-facing error logic, maps SATPInternalErrors to user friendly errors
export class SATPError extends Error {}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
export class Stage0ClientService extends SATPService {
public static readonly SATP_STAGE = "0";
public static readonly SERVICE_TYPE = SATPServiceType.Client;
public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`;

constructor(ops: ISATPClientServiceOptions) {
// for now stage1serverservice does not have any different options than the SATPService class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
export class Stage1ClientService extends SATPService {
public static readonly SATP_STAGE = "1";
public static readonly SERVICE_TYPE = SATPServiceType.Client;
public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`;

constructor(ops: ISATPClientServiceOptions) {
// for now stage1serverservice does not have any different options than the SATPService class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
export class Stage2ClientService extends SATPService {
public static readonly SATP_STAGE = "2";
public static readonly SERVICE_TYPE = SATPServiceType.Client;
public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`;

private bridgeManager: SATPBridgesManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
export class Stage3ClientService extends SATPService {
public static readonly SATP_STAGE = "3";
public static readonly SERVICE_TYPE = SATPServiceType.Client;
public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`;

private bridgeManager: SATPBridgesManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,42 @@ import {
ILoggerOptions,
} from "@hyperledger/cactus-common";
import { SATPBridgesManager } from "../../gol/satp-bridges-manager";
import { SatpStage0Service } from "../../generated/proto/cacti/satp/v02/stage_0_connect";
import { SatpStage1Service } from "../../generated/proto/cacti/satp/v02/stage_1_connect";
import { SatpStage2Service } from "../../generated/proto/cacti/satp/v02/stage_2_connect";
import { SatpStage3Service } from "../../generated/proto/cacti/satp/v02/stage_3_connect";

export enum SATPServiceType {
Server = "Server",
Client = "Client",
}

export type SATPStagesV02 = "0" | "1" | "2" | "3";

export type ISATPServiceOptions = {
serviceName: string;
stage: "0" | "1" | "2" | "3";
stage: SATPStagesV02;
loggerOptions: ILoggerOptions;
signer: JsObjectSigner;
serviceType: SATPServiceType;
bridgeManager?: SATPBridgesManager;
};

export interface SATPServiceStatic {
new (options: ISATPServiceOptions): SATPService;
readonly SERVICE_TYPE: SATPServiceType;
readonly SATP_STAGE: string;
// service name serves as an internal, hardcoded service name. One can assign a more user-friendly service name via the SATPService constructor
readonly SATP_SERVICE_INTERNAL_NAME: string;
get ServiceType(): SATPServiceType;
}

export type SATPServiceInstance =
| (typeof SatpStage0Service & SATPServiceStatic)
| (typeof SatpStage1Service & SATPServiceStatic)
| (typeof SatpStage2Service & SATPServiceStatic)
| (typeof SatpStage3Service & SATPServiceStatic);

export type ISATPServerServiceOptions = ISATPServiceOptions;

export type ISATPClientServiceOptions = ISATPServiceOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
saveHash,
saveSignature,
} from "../../session-utils";
import { SupportedChain } from "../../types";
import { SATPSession } from "../../../core/satp-session";
import {
SATPService,
Expand All @@ -36,6 +35,7 @@ import {
export class Stage0ServerService extends SATPService {
public static readonly SATP_STAGE = "0";
public static readonly SERVICE_TYPE = SATPServiceType.Server;
public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`;

constructor(ops: ISATPServerServiceOptions) {
// for now stage0serverservice does not have any different options than the SATPService class
Expand Down Expand Up @@ -234,6 +234,9 @@ export class Stage0ServerService extends SATPService {
const stepTag = `checkTransferProposalRequestMessage()`;
const fnTag = `${this.getServiceIdentifier()}#${stepTag}`;

// todo use session;
session;

if (
request.context == undefined ||
request.context.version == undefined ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
CommonSatp,
} from "../../../generated/proto/cacti/satp/v02/common/message_pb";
// eslint-disable-next-line prettier/prettier
import { ACCEPTANCE, SessionData } from "../../../generated/proto/cacti/satp/v02/common/session_pb";
import {
ACCEPTANCE,
SessionData,
} from "../../../generated/proto/cacti/satp/v02/common/session_pb";
import { SATP_VERSION } from "../../constants";
import {
bufArray2HexStr,
Expand Down Expand Up @@ -52,6 +55,7 @@ import {
export class Stage1ServerService extends SATPService {
public static readonly SATP_STAGE = "1";
public static readonly SERVICE_TYPE = SATPServiceType.Server;
public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`;

constructor(ops: ISATPServerServiceOptions) {
// for now stage1serverservice does not have any different options than the SATPService class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
export class Stage2ServerService extends SATPService {
public static readonly SATP_STAGE = "2";
public static readonly SERVICE_TYPE = SATPServiceType.Server;
public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`;

constructor(ops: ISATPServerServiceOptions) {
const commonOptions: ISATPServiceOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
export class Stage3ServerService extends SATPService {
public static readonly SATP_STAGE = "3";
public static readonly SERVICE_TYPE = SATPServiceType.Server;
public static readonly SATP_SERVICE_INTERNAL_NAME = `stage-${this.SATP_STAGE}-${SATPServiceType[this.SERVICE_TYPE].toLowerCase()}`;

private bridgeManager: SATPBridgesManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,20 @@ import { ValidatorOptions } from "class-validator";
import { BLODispatcher } from "../blo/dispatcher";
import { ISignerKeyPairs } from "@hyperledger/cactus-common/dist/lib/main/typescript/signer-key-pairs";
import { SATPSession } from "./satp-session";
import { SatpStage0Service } from "../generated/proto/cacti/satp/v02/stage_0_connect";
import { SatpStage1Service } from "../generated/proto/cacti/satp/v02/stage_1_connect";
import { SatpStage2Service } from "../generated/proto/cacti/satp/v02/stage_2_connect";
import { SatpStage3Service } from "../generated/proto/cacti/satp/v02/stage_3_connect";
import { ConnectRouter } from "@connectrpc/connect";
import { SATPGateway } from "../plugin-satp-hermes-gateway";
import { SATPService } from "../types/satp-protocol";
import { PromiseClient as PromiseConnectClient } from "@connectrpc/connect";
import { IPrivacyPolicyValue } from "@hyperledger/cactus-plugin-bungee-hermes/dist/lib/main/typescript/view-creation/privacy-policies";
import { IMergePolicyValue } from "@hyperledger/cactus-plugin-bungee-hermes/dist/lib/main/typescript/view-merging/merge-policies";
import { NetworkBridge } from "./stage-services/satp-bridge/network-bridge";
import { SATPServiceInstance } from "./stage-services/satp-service";

export type SATPConnectHandler = (
gateway: SATPGateway,
service: SATPService,
) => (router: ConnectRouter) => void;

export type SATPServiceClient =
| typeof SatpStage0Service
| typeof SatpStage1Service
| typeof SatpStage2Service
| typeof SatpStage3Service;
import { NetworkBridge } from "./stage-services/satp-bridge/network-bridge";

export enum CurrentDrafts {
Core = "Core",
Architecture = "Architecture",
Expand Down Expand Up @@ -55,7 +46,7 @@ export type GatewayChannel = {
toGatewayID: string;
sessions: Map<string, SATPSession>;
supportedDLTs: SupportedChain[];
clients: Map<string, PromiseConnectClient<SATPServiceClient>>;
clients: Map<string, PromiseConnectClient<SATPServiceInstance>>;
};

export type Address =
Expand Down Expand Up @@ -126,3 +117,4 @@ export interface SATPBridgeConfig {
network: NetworkBridge;
logLevel?: LogLevelDesc;
}
export { SATPServiceInstance };
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
GatewayIdentity,
GatewayChannel,
SupportedChain,
SATPServiceClient,
SATPServiceInstance,
} from "../core/types";
import {
PromiseClient as PromiseConnectClient,
Expand Down Expand Up @@ -204,7 +204,7 @@ export class GatewayOrchestrator {

private createConnectClients(
identity: GatewayIdentity,
): Map<string, PromiseConnectClient<SATPServiceClient>> {
): Map<string, PromiseConnectClient<SATPServiceInstance>> {
// one function for each client type; aggregate in array
const transport = createConnectTransport({
baseUrl: identity.address + ":" + identity.gatewayGrpcPort,
Expand All @@ -213,7 +213,7 @@ export class GatewayOrchestrator {

const clients: Map<
string,
PromiseConnectClient<SATPServiceClient>
PromiseConnectClient<SATPServiceInstance>
> = new Map();

clients.set("0", this.createStage0ServiceClient(transport));
Expand Down
Loading

0 comments on commit 7da3f27

Please sign in to comment.