Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post release fixes #57

Merged
merged 11 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Build & Deploy
on:
push:
branches: [ main ]
pull_request:

jobs:
build:
Expand Down Expand Up @@ -36,8 +37,14 @@ jobs:

- name: Get docker tag
id: tag
run: echo "IMAGE_TAG=latest" >> $GITHUB_OUTPUT

run: |
echo "${GITHUB_REF##*/}"
if [[ "${GITHUB_REF##*/}" == "main" ]]; then
echo "IMAGE_TAG=latest" >> $GITHUB_OUTPUT
else
echo "IMAGE_TAG=${GITHUB_SHA}" >> $GITHUB_OUTPUT
fi

- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
Expand Down Expand Up @@ -80,4 +87,5 @@ jobs:
NETSTR_IMAGE: "ghcr.io/bezysoftware/netstr:${{ env.IMAGE_TAG }}"
NETSTR_ENVIRONMENT: dev
NETSTR_ENVIRONMENT_LONG: Development
NETSTR_PORT: 8081
NETSTR_PORT: 8081
NETSTR_VERSION: ${{ github.sha }}
53 changes: 0 additions & 53 deletions .github/workflows/build.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ jobs:
NETSTR_DB_PASSWORD: ${{ secrets.NETSTR_DB_PASSWORD }}
NETSTR_IMAGE: "bezysoftware/netstr:${{ env.IMAGE_TAG }}"
NETSTR_ENVIRONMENT: prod
NETSTR_PORT: 8080
NETSTR_PORT: 8080
NETSTR_VERSION: ${{ env.IMAGE_TAG }}
1 change: 0 additions & 1 deletion Netstr.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{320F094E-4B63-40D7-8D8B-AB5B01F6FCB0}"
ProjectSection(SolutionItems) = preProject
.github\workflows\build-deploy.yml = .github\workflows\build-deploy.yml
.github\workflows\build.yml = .github\workflows\build.yml
.github\workflows\manual.yml = .github\workflows\manual.yml
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
Expand Down
1 change: 1 addition & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- "${NETSTR_PORT:-8080}:8080"
environment:
ConnectionStrings__NetstrDatabase: Host=db:5432;Database=Netsrt;Username=Netstr;Password=${NETSTR_DB_PASSWORD:?Password must be set}
RelayInformation__Version: ${NETSTR_VERSION:-v0.0.0}
ASPNETCORE_ENVIRONMENT: ${NETSTR_ENVIRONMENT_LONG}
depends_on:
- db
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;

namespace Netstr.Extensions
namespace Netstr.Json
{
public static class JsonExtensions
{
Expand Down
29 changes: 29 additions & 0 deletions src/Netstr/Json/NostrJsonEncoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Text.Encodings.Web;

namespace Netstr.Json
{
/// <summary>
/// Json encoder for nostr events which follows NIP-01's character escaping rules.
/// </summary>
public class NostrJsonEncoder : JavaScriptEncoder
{
private static int[] EscapableCharacters = [0x0A, 0x22, 0x5C, 0x0D, 0x09, 0x08, 0x0C];

public override int MaxOutputCharactersPerInputCharacter => JavaScriptEncoder.Default.MaxOutputCharactersPerInputCharacter;

public override unsafe int FindFirstCharacterToEncode(char* text, int textLength)
{
return JavaScriptEncoder.UnsafeRelaxedJsonEscaping.FindFirstCharacterToEncode(text, textLength);
}

public override unsafe bool TryEncodeUnicodeScalar(int unicodeScalar, char* buffer, int bufferLength, out int numberOfCharactersWritten)
{
return JavaScriptEncoder.UnsafeRelaxedJsonEscaping.TryEncodeUnicodeScalar(unicodeScalar, buffer, bufferLength, out numberOfCharactersWritten);
}

public override bool WillEncode(int unicodeScalar)
{
return EscapableCharacters.Contains(unicodeScalar);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json.Serialization;
using System.Text.Json;

namespace Netstr.Converters
namespace Netstr.Json
{
/// <summary>
/// Converts Unix time to DateTimeOffset.
Expand Down
2 changes: 1 addition & 1 deletion src/Netstr/Messaging/Events/EventParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Netstr.Extensions;
using Netstr.Json;
using Netstr.Messaging.Models;
using System.Text.Json;

Expand Down
5 changes: 3 additions & 2 deletions src/Netstr/Messaging/Events/Validators/EventHashValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Netstr.Messaging.Models;
using Netstr.Json;
using Netstr.Messaging.Models;
using System.Security.Cryptography;
using System.Text.Encodings.Web;
using System.Text.Json;
Expand All @@ -12,7 +13,7 @@ public class EventHashValidator : IEventValidator
{
private static JsonSerializerOptions serializerOptions = new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
Encoder = new NostrJsonEncoder()
};

public string? Validate(Event e, ClientContext context)
Expand Down
2 changes: 1 addition & 1 deletion src/Netstr/Messaging/MessageDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task DispatchMessageAsync(IWebSocketAdapter sender, string message)
}
catch (MessageProcessingException ex)
{
this.logger.LogError(ex, $"Failed to process message: {message}");
this.logger.LogWarning(ex, $"Failed to process message: {message}");
await sender.SendAsync(ex.GetSenderReply());
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Options;
using Netstr.Data;
using Netstr.Extensions;
using Netstr.Json;
using Netstr.Messaging.Models;
using Netstr.Messaging.Subscriptions;
using Netstr.Messaging.Subscriptions.Validators;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Netstr.Extensions;
using Netstr.Json;
using Netstr.Messaging.Models;
using System.Text.Json;

Expand Down
2 changes: 1 addition & 1 deletion src/Netstr/Messaging/Models/Event.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Netstr.Converters;
using Netstr.Json;
using System.Numerics;
using System.Text.Json.Serialization;

Expand Down
2 changes: 1 addition & 1 deletion src/Netstr/Messaging/Models/SubscriptionFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Netstr.Converters;
using Netstr.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down
1 change: 1 addition & 0 deletions src/Netstr/Netstr.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileFile>..\..\Dockerfile</DockerfileFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 7 additions & 4 deletions src/Netstr/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
<td>Software</td>
<td><a href="@Model.RelayInformation.Software" target="_blank">@Model.RelayInformation.Software</a></td>
</tr>
<tr>
<td>Environment</td>
<td>@Model.Environment</td>
</tr>
@if (!string.IsNullOrEmpty(Model.Environment))
{
<tr>
<td>Environment</td>
<td>@Model.Environment</td>
</tr>
}
</table>

<div class="connect-box">
Expand Down
6 changes: 3 additions & 3 deletions src/Netstr/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
},
"Limits": {
"MaxPayloadSize": 524288,
"MaxInitialLimit": 100,
"MaxInitialLimit": 1000,
"MinPowDifficulty": 0,
"MaxFilters": 20,
"MaxSubscriptions": 30,
"MaxSubscriptions": 50,
"MaxSubscriptionIdLength": 128,
"MaxSubscriptionLimit": 1000,
"MaxEventTags": 1000,
Expand All @@ -46,7 +46,7 @@
"RelayInformation": {
"Name": "netstr.io",
"Description": "A nostr relay",
"PublicKey": "npub1q84c9lheynjl33u6ha5ulfdd25yw0p90w2zqx6f23w6cjrn7w76s373p35",
"PublicKey": "01eb82fef924e5f8c79abf69cfa5ad5508e784af728403692a8bb5890e7e77b5",
"Contact": "[email protected]",
"SupportedNips": [ 1, 2, 4, 9, 11, 13, 17, 40, 42, 45, 70 ],
"Version": "v0.0.0"
Expand Down
Binary file added src/Netstr/wwwroot/favicon.ico
Binary file not shown.
16 changes: 8 additions & 8 deletions test/Netstr.Tests/NIPs/01.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: NIP-01
Feature: NIP-01
Defines the basic protocol that should be implemented by everybody.

Background:
Expand All @@ -20,21 +20,21 @@ Scenario: Invalid messages are discarded, valid ones accepted
| Kinds |
| 1 |
And Bob publishes events
| Id | Content | Kind | CreatedAt | Signature | Tags |
| ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | Hello 1 | 1 | 1722337838 | | |
| a6d166e834e78827af0770f31f15b13a772f281ad880f43ce12c24d4e3d0e346 | Hello 1 | 1 | 1722337838 | Invalid | |
| 9a6b4cefcd17f3bf7fb03c02da044c628836a118c47d5b92503c1d2bdb796296 | Hi ' \" \b \t \r \n | 1 | 1722337838 | | |
| 50ed63c449df67d89e9964a27a26abbf214ca155b03915067a5a0f75618802bb | Hello | 1 | 1722337838 | | [[]] |
| Id | Content | Kind | CreatedAt | Signature | Tags |
| ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | Hello 1 | 1 | 1722337838 | | |
| a6d166e834e78827af0770f31f15b13a772f281ad880f43ce12c24d4e3d0e346 | Hello 1 | 1 | 1722337838 | Invalid | |
| bb5d2fe5b2c16c676d87ef446fa38581b9fa45e2e50ba89568664abf4e1d1396 | Hi ' \" \b \t \r \n 🎉 #nostr | 1 | 1722337838 | | |
| 50ed63c449df67d89e9964a27a26abbf214ca155b03915067a5a0f75618802bb | Hello | 1 | 1722337838 | | [[]] |
Then Bob receives messages
| Type | Id | Success |
| OK | ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | false |
| OK | a6d166e834e78827af0770f31f15b13a772f281ad880f43ce12c24d4e3d0e346 | false |
| OK | 9a6b4cefcd17f3bf7fb03c02da044c628836a118c47d5b92503c1d2bdb796296 | true |
| OK | bb5d2fe5b2c16c676d87ef446fa38581b9fa45e2e50ba89568664abf4e1d1396 | true |
| OK | 50ed63c449df67d89e9964a27a26abbf214ca155b03915067a5a0f75618802bb | false |
And Alice receives a message
| Type | Id | EventId |
| EOSE | abcd | |
| EVENT | abcd | 9a6b4cefcd17f3bf7fb03c02da044c628836a118c47d5b92503c1d2bdb796296 |
| EVENT | abcd | bb5d2fe5b2c16c676d87ef446fa38581b9fa45e2e50ba89568664abf4e1d1396 |

Scenario: Newly subscribed client receives matching events, EOSE and future events
Bob publishes events which are stored by the relay before any subscription exists.
Expand Down
8 changes: 4 additions & 4 deletions test/Netstr.Tests/NIPs/01.feature.cs

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

2 changes: 1 addition & 1 deletion test/Netstr.Tests/NIPs/Types.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Netstr.Extensions;
using Netstr.Json;
using Netstr.Messaging.Models;
using System.Net.WebSockets;
using System.Text.Json;
Expand Down