Skip to content

Commit

Permalink
Merge pull request #1101 from golemfactory/beta
Browse files Browse the repository at this point in the history
Beta -> master
  • Loading branch information
grisha87 authored Oct 11, 2024
2 parents 9f385e3 + baa402e commit 3e9d9e5
Show file tree
Hide file tree
Showing 17 changed files with 374 additions and 145 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const order: MarketOrderSpec = {
},
market: {
// We're only going to rent the provider for 5 minutes max
rentHours: 5 / 60,
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
Expand Down
14 changes: 7 additions & 7 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ import { GolemNetwork } from "@golem-sdk/golem-js";
try {
await glm.connect();

const retnal = await glm.oneOf({
const rental = await glm.oneOf({
order: {
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
// You have to be now explicit about about your terms and expectatios from the market
// You have to be now explicit about about your terms and expectations from the market
market: {
rentHours: 5 / 60,
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
Expand Down Expand Up @@ -132,9 +132,9 @@ import { GolemNetwork } from "@golem-sdk/golem-js";
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
// You have to be now explicit about about your terms and expectatios from the market
// You have to be now explicit about about your terms and expectations from the market
market: {
rentHours: 5 / 60,
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
Expand All @@ -147,13 +147,13 @@ import { GolemNetwork } from "@golem-sdk/golem-js";

const inputs = [1, 2, 3, 4, 5];

// You still take the necessary precaucions, pipeline your work and processing
// You still take the necessary precautions, pipeline your work and processing
const results = await Promise.allSettled(
inputs.map((input) =>
// 🌟🌟 You access rentals from the pool
pool.withRental((rental) =>
rental
// 🌟🌟🌟 You issue the comands as in case of a single-provider scenario
// 🌟🌟🌟 You issue the commands as in case of a single-provider scenario
.getExeUnit()
.then((exe) => exe.run(`echo 'Hello ${input}`))
.then((res) => res.stdout),
Expand Down
4 changes: 2 additions & 2 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
// We're only going to rent the provider for 5 minutes max
rentHours: 5 / 60,
// We're only going to rent the provider for 15 minutes max
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
Expand Down
2 changes: 1 addition & 1 deletion examples/rental-model/advanced/local-image/local-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const getImagePath = (path: string) => new URL(path, import.meta.url).toString()
},
},
market: {
rentHours: 5 / 60,
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 1,
Expand Down
77 changes: 18 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"marketplace"
],
"main": "dist/golem-js.js",
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -87,9 +86,7 @@
"@commitlint/cli": "^19.0.3",
"@commitlint/config-conventional": "^19.0.3",
"@johanblumenberg/ts-mockito": "^1.0.43",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
Expand All @@ -100,7 +97,7 @@
"@types/eventsource": "^1.1.15",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.20",
"@types/node": "^18.19.55",
"@types/semver": "^7.5.8",
"@types/supertest": "^6.0.2",
"@types/tmp": "^0.2.6",
Expand Down
2 changes: 0 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import alias from "@rollup/plugin-alias";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import nodePolyfills from "rollup-plugin-polyfill-node";
Expand Down
4 changes: 2 additions & 2 deletions src/golem-network/golem-network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MarketApiAdapter, PaymentApiAdapter } from "../shared/yagna";
import { ActivityApiAdapter } from "../shared/yagna/adapters/activity-api-adapter";
import { GolemNetwork, MarketOrderSpec } from "./golem-network";
import { _, instance, mock, reset, spy, verify, when } from "@johanblumenberg/ts-mockito";
import { GftpStorageProvider } from "../shared/storage";
import { WebSocketStorageProvider } from "../shared/storage";

const order: MarketOrderSpec = Object.freeze({
demand: {
Expand All @@ -34,7 +34,7 @@ const mockYagna = mock(YagnaApi);
const mockPaymentApi = mock(PaymentApiAdapter);
const mockActivityApi = mock(ActivityApiAdapter);
const mockMarketApi = mock(MarketApiAdapter);
const mockStorageProvider = mock(GftpStorageProvider);
const mockStorageProvider = mock(WebSocketStorageProvider);

afterEach(() => {
reset(mockYagna);
Expand Down
27 changes: 13 additions & 14 deletions src/golem-network/golem-network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { anyAbortSignal, createAbortSignalFromTimeout, defaultLogger, isNode, Logger, YagnaApi } from "../shared/utils";
import { anyAbortSignal, createAbortSignalFromTimeout, defaultLogger, Logger, YagnaApi } from "../shared/utils";
import {
Demand,
DraftOfferProposalPool,
Expand Down Expand Up @@ -29,17 +29,13 @@ import { ProposalRepository } from "../shared/yagna/repository/proposal-reposito
import { CacheService } from "../shared/cache/CacheService";
import { DemandRepository } from "../shared/yagna/repository/demand-repository";
import { IDemandRepository, OrderDemandOptions } from "../market/demand";
import { GftpServerAdapter } from "../shared/storage/GftpServerAdapter";
import {
GftpStorageProvider,
NullStorageProvider,
StorageProvider,
WebSocketBrowserStorageProvider,
} from "../shared/storage";
import { StorageServerAdapter } from "../shared/storage/StorageServerAdapter";
import { GftpStorageProvider, NullStorageProvider, StorageProvider, WebSocketStorageProvider } from "../shared/storage";
import { DataTransferProtocol } from "../shared/types";
import { NetworkApiAdapter } from "../shared/yagna/adapters/network-api-adapter";
import { IProposalRepository } from "../market/proposal";
import { Subscription } from "rxjs";
import { GolemConfigError } from "../shared/error/golem-error";

/**
* Instance of an object or a factory function that you can call `new` on.
Expand Down Expand Up @@ -105,7 +101,7 @@ export interface GolemNetworkOptions {

/**
* Set the data transfer protocol to use for file transfers.
* Default is `gftp`.
* Default is `ws`.
*/
dataTransferProtocol?: DataTransferProtocol;

Expand Down Expand Up @@ -228,7 +224,7 @@ export class GolemNetwork {

constructor(options: Partial<GolemNetworkOptions> = {}) {
const optDefaults: GolemNetworkOptions = {
dataTransferProtocol: isNode ? "gftp" : "ws",
dataTransferProtocol: "ws",
};

this.options = {
Expand Down Expand Up @@ -285,7 +281,7 @@ export class GolemNetwork {
this.options.override?.marketApi ||
new MarketApiAdapter(this.yagna, agreementRepository, proposalRepository, demandRepository, this.logger),
networkApi: this.options.override?.networkApi || new NetworkApiAdapter(this.yagna),
fileServer: this.options.override?.fileServer || new GftpServerAdapter(this.storageProvider),
fileServer: this.options.override?.fileServer || new StorageServerAdapter(this.storageProvider),
};
this.network = getFactory(NetworkModuleImpl, this.options.override?.network)(this.services);
this.market = getFactory(MarketModuleImpl, this.options.override?.market)(
Expand Down Expand Up @@ -655,13 +651,16 @@ export class GolemNetwork {
private createStorageProvider(): StorageProvider {
if (typeof this.options.dataTransferProtocol === "string") {
switch (this.options.dataTransferProtocol) {
case "gftp":
return new GftpStorageProvider(this.logger);
case "ws":
return new WebSocketBrowserStorageProvider(this.yagna, {
return new WebSocketStorageProvider(this.yagna, {
logger: this.logger,
});
case "gftp":
default:
return new GftpStorageProvider(this.logger);
throw new GolemConfigError(
`Unsupported data transfer protocol ${this.options.dataTransferProtocol}. Supported protocols are "gftp" and "ws"`,
);
}
} else if (this.options.dataTransferProtocol !== undefined) {
return this.options.dataTransferProtocol;
Expand Down
15 changes: 15 additions & 0 deletions src/network/tcp-proxy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
jest.mock("../shared/utils", () => ({
checkAndThrowUnsupportedInBrowserError: () => {
throw new GolemUserError("Not supported in browser");
},
}));

import { GolemUserError } from "../shared/error/golem-error";

import { TcpProxy } from "./tcp-proxy";

describe("TCP Proxy in browser", () => {
test("Uses the checkAndThrowUnsupportedInBrowserError util to throw when the function detects browser environment", () => {
expect(() => new TcpProxy("ws://fake.url", "fake-app-key")).toThrow("Not supported in browser");
});
});
6 changes: 4 additions & 2 deletions src/network/tcp-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import net from "net";
import { WebSocket } from "ws";
import { EventEmitter } from "eventemitter3";
import { defaultLogger, Logger } from "../shared/utils";
import { checkAndThrowUnsupportedInBrowserError, defaultLogger, Logger } from "../shared/utils";
import { Buffer } from "buffer";

export interface TcpProxyEvents {
Expand Down Expand Up @@ -64,8 +64,10 @@ export class TcpProxy {
/**
* Additional options of the proxy
*/
options: Partial<TcpProxyOptions>,
options: Partial<TcpProxyOptions> = {},
) {
checkAndThrowUnsupportedInBrowserError("TCP Proxy");

this.heartBeatSec = options.heartBeatSec ?? 10;
this.logger = options.logger ? options.logger.child("tcp-proxy") : defaultLogger("tcp-proxy");

Expand Down
Loading

0 comments on commit 3e9d9e5

Please sign in to comment.