Skip to content

Commit

Permalink
Moved all web-compatible parts of the S5 Node implementation to the l…
Browse files Browse the repository at this point in the history
…ib5 package
  • Loading branch information
redsolver committed Mar 9, 2024
1 parent 1dfd599 commit ac7661b
Show file tree
Hide file tree
Showing 28 changed files with 173 additions and 1,796 deletions.
8 changes: 5 additions & 3 deletions bin/s5_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void main(List<String> arguments) async {
logger.info('');

final node = S5Node(
config,
config: config,
logger: logger,
rust: rust,
crypto: crypto,
Expand Down Expand Up @@ -90,8 +90,9 @@ port = 5050
[p2p.peers]
initial = [
'wss://[email protected]/s5/p2p',
'wss://[email protected]/s5/p2p',
'wss://[email protected]/s5/p2p',
'wss://[email protected]/s5/p2p',
]
''';

Expand All @@ -116,7 +117,8 @@ bind = '0.0.0.0'
[p2p.peers]
initial = [
'wss://[email protected]/s5/p2p',
'wss://[email protected]/s5/p2p',
'wss://[email protected]/s5/p2p',
'wss://[email protected]/s5/p2p',
]
''';
45 changes: 0 additions & 45 deletions lib/api.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ! S5 node version
const nodeVersion = '0.13.5';
const nodeVersion = '0.14.1';

// ! default chunk size for hashes
const defaultChunkSize = 256 * 1024;
Expand Down
8 changes: 8 additions & 0 deletions lib/crypto/implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:typed_data';

import 'package:cryptography/cryptography.dart';
import 'package:lib5/lib5.dart';
import 'package:lib5/util.dart';

import 'package:s5_server/rust/bridge_definitions.dart';

Expand Down Expand Up @@ -106,4 +107,11 @@ class RustCryptoImplementation extends CryptoImplementation {
plaintext: plaintext,
);
}

@override
Future<Uint8List> hashBlake3File(
{required int size, required OpenReadFunction openRead}) {
// TODO: implement hashBlake3File
throw UnimplementedError();
}
}
4 changes: 3 additions & 1 deletion lib/download/open_read.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'dart:io';
import 'dart:math';
import 'dart:typed_data';

// TODO Move this to lib5 (with generic kv FS abstraction/Stream)

import 'package:http/http.dart';
import 'package:lib5/constants.dart';
import 'package:lib5/lib5.dart';
import 'package:lib5/node.dart';
import 'package:lib5/util.dart';
import 'package:path/path.dart';

import 'package:s5_server/download/uri_provider.dart';
import 'package:s5_server/node.dart';

final httpClient = Client();
Expand Down
120 changes: 0 additions & 120 deletions lib/download/uri_provider.dart

This file was deleted.

21 changes: 9 additions & 12 deletions lib/http_api/http_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:alfred/alfred.dart';
// ignore: implementation_imports
import 'package:alfred/src/type_handlers/websocket_type_handler.dart';
import 'package:base_codecs/base_codecs.dart';
import 'package:http/http.dart';
import 'package:lib5/constants.dart';
import 'package:lib5/lib5.dart';
import 'package:lib5/node.dart';
import 'package:lib5/util.dart';
import 'package:s5_msgpack/s5_msgpack.dart';
import 'package:mime/mime.dart';
import 'package:path/path.dart';
import 'package:s5_server/accounts/account.dart';

import 'package:s5_server/accounts/account.dart';
import 'package:s5_server/constants.dart';
import 'package:s5_server/download/uri_provider.dart';
import 'package:s5_server/http_api/admin.dart';
import 'package:s5_server/node.dart';
import 'package:s5_server/service/accounts.dart';
import 'package:s5_server/service/p2p.dart';
import 'package:s5_server/util/uid.dart';
import 'package:s5_server/util/multipart.dart';
import 'package:s5_server/util/uid.dart';
import 'serve_chunked_file.dart';

class HttpAPIServer {
Expand Down Expand Up @@ -415,7 +412,7 @@ class HttpAPIServer {
request.headers[h.key] = h.value;
}

final response = await httpClient.send(request);
final response = await node.httpClient.send(request);

if (response.statusCode < 200 || response.statusCode >= 300) {
throw 'HTTP ${response.statusCode}';
Expand Down Expand Up @@ -604,7 +601,7 @@ class HttpAPIServer {
throw 'This endpoint does not support resolver CIDs yet';
}

final metadata = await node.getMetadataByCID(cid);
final metadata = await node.downloadMetadata(cid);

if (cid.type != cidTypeBridge) {
setUnlimitedCacheHeader(res);
Expand Down Expand Up @@ -795,7 +792,7 @@ class HttpAPIServer {
res.statusCode = 204;
});

app.get('/s5/registry/subscription', (req, res) async {
/* app.get('/s5/registry/subscription', (req, res) async {
final auth = await node.checkAuth(req, 's5/registry/subscription');
if (auth.denied) return res.unauthorized(auth);
Expand All @@ -810,7 +807,7 @@ class HttpAPIServer {
);
stream.map((sre) {
return node.registry.serializeRegistryEntry(sre);
return sre.serialize();
}).listen((event) {
webSocket.add(event);
});
Expand All @@ -820,7 +817,7 @@ class HttpAPIServer {
// TODO Clean up subscriptions
},
);
});
}); */

final authorization = node.config['http']?['api']?['authorization'];

Expand Down Expand Up @@ -963,7 +960,7 @@ class HttpAPIServer {
cid = CID.fromBytes(res.data.sublist(1));
}

final metadata = await node.getMetadataByCID(cid) as WebAppMetadata;
final metadata = await node.downloadMetadata(cid) as WebAppMetadata;

WebAppMetadataFileReference? servedFile;

Expand Down
10 changes: 1 addition & 9 deletions lib/http_api/serve_chunked_file.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';

import 'package:belatuk_range_header/belatuk_range_header.dart';
import 'package:http/http.dart';
import 'package:lib5/lib5.dart';
import 'package:lib5/util.dart';
import 'package:path/path.dart';
import 'package:s5_server/download/open_read.dart';

import 'package:s5_server/download/uri_provider.dart';
import 'package:s5_server/logger/base.dart';
import 'package:s5_server/download/open_read.dart';
import 'package:s5_server/node.dart';

final httpClient = Client();

Future handleChunkedFile(
HttpRequest req,
HttpResponse res,
Expand Down
7 changes: 0 additions & 7 deletions lib/logger/base.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/logger/console.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:io';
import 'package:tint/tint.dart';

import 'base.dart';
import 'package:lib5/util.dart';
import 'package:tint/tint.dart';

class ConsoleLogger extends Logger {
final String prefix;
Expand Down
Loading

0 comments on commit ac7661b

Please sign in to comment.