Skip to content

Commit

Permalink
Rename Address to ConnectionId (#239)
Browse files Browse the repository at this point in the history
## Description of Changes

Companion to [Rename `Address` to
`ConnectionId`](clockworklabs/SpacetimeDB#2220).
See that PR's description for more.

Like all the SDKs, this PR does not change the SDK's behavior; the SDK
still generates a connection ID locally and passes it through the HTTP
API. This is not exposed to users, and can be changed in a follow-up.

Also, use `/usr/bin/env bash` instead of `/bin/bash` in tools, for
portability reasons.

## API

 - [x] This is an API breaking change to the SDK

`Address` is renamed to `ConnectionId`.

## Requires SpacetimeDB PRs

- clockworklabs/SpacetimeDB#2220
- 
## Testsuite
*If you would like to run the your SDK changes in this PR against a
specific SpacetimeDB branch, specify that here. This can be a branch
name or a link to a PR.*

SpacetimeDB branch name: phoebe/rename-address-to-connection-id

## Testing

- [x] Pretty much just automated testing.
- [x] @kazimuth will need to update and run Blackholio.

---------

Co-authored-by: James Gilles <[email protected]>
  • Loading branch information
gefjon and kazimuth authored Feb 10, 2025
1 parent 80f951c commit 124a1cb
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 51 deletions.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public record ReducerEvent<R>(
Timestamp Timestamp,
Status Status,
Identity CallerIdentity,
Address? CallerAddress,
ConnectionId? CallerConnectionId,
U128? EnergyConsumed,
R Reducer
);
Expand Down
8 changes: 4 additions & 4 deletions src/SpacetimeDB/ClientApi/IdentityToken.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public sealed partial class IdentityToken
public SpacetimeDB.Identity Identity;
[DataMember(Name = "token")]
public string Token;
[DataMember(Name = "address")]
public SpacetimeDB.Address Address;
[DataMember(Name = "connection_id")]
public SpacetimeDB.ConnectionId ConnectionId;

public IdentityToken(
SpacetimeDB.Identity Identity,
string Token,
SpacetimeDB.Address Address
SpacetimeDB.ConnectionId ConnectionId
)
{
this.Identity = Identity;
this.Token = Token;
this.Address = Address;
this.ConnectionId = ConnectionId;
}

public IdentityToken()
Expand Down
8 changes: 4 additions & 4 deletions src/SpacetimeDB/ClientApi/TransactionUpdate.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public sealed partial class TransactionUpdate
public SpacetimeDB.Timestamp Timestamp;
[DataMember(Name = "caller_identity")]
public SpacetimeDB.Identity CallerIdentity;
[DataMember(Name = "caller_address")]
public SpacetimeDB.Address CallerAddress;
[DataMember(Name = "caller_connection_id")]
public SpacetimeDB.ConnectionId CallerConnectionId;
[DataMember(Name = "reducer_call")]
public ReducerCallInfo ReducerCall;
[DataMember(Name = "energy_quanta_used")]
Expand All @@ -32,7 +32,7 @@ public TransactionUpdate(
UpdateStatus Status,
SpacetimeDB.Timestamp Timestamp,
SpacetimeDB.Identity CallerIdentity,
SpacetimeDB.Address CallerAddress,
SpacetimeDB.ConnectionId CallerConnectionId,
ReducerCallInfo ReducerCall,
EnergyQuanta EnergyQuantaUsed,
SpacetimeDB.TimeDuration TotalHostExecutionDuration
Expand All @@ -41,7 +41,7 @@ SpacetimeDB.TimeDuration TotalHostExecutionDuration
this.Status = Status;
this.Timestamp = Timestamp;
this.CallerIdentity = CallerIdentity;
this.CallerAddress = CallerAddress;
this.CallerConnectionId = CallerConnectionId;
this.ReducerCall = ReducerCall;
this.EnergyQuantaUsed = EnergyQuantaUsed;
this.TotalHostExecutionDuration = TotalHostExecutionDuration;
Expand Down
6 changes: 3 additions & 3 deletions src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ struct DbOp
[Obsolete]
public event Action<ReducerEvent<Reducer>>? onUnhandledReducerError;

public readonly Address Address = Address.Random();
public readonly ConnectionId ConnectionId = ConnectionId.Random();
public Identity? Identity { get; private set; }

internal WebSocket webSocket;
Expand Down Expand Up @@ -613,7 +613,7 @@ PreProcessedMessage PreProcessMessage(UnprocessedMessage unprocessed)
_ => throw new InvalidOperationException()
},
transactionUpdate.CallerIdentity,
transactionUpdate.CallerAddress,
transactionUpdate.CallerConnectionId,
transactionUpdate.EnergyQuantaUsed.Quanta,
ToReducer(transactionUpdate));
}
Expand Down Expand Up @@ -705,7 +705,7 @@ void IDbConnection.Connect(string? token, string uri, string addressOrName, Comp
{
try
{
await webSocket.Connect(token, uri, addressOrName, Address, compression, light);
await webSocket.Connect(token, uri, addressOrName, ConnectionId, compression, light);
}
catch (Exception e)
{
Expand Down
4 changes: 2 additions & 2 deletions src/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public WebSocket(ConnectOptions options)

public bool IsConnected { get { return Ws != null && Ws.State == WebSocketState.Open; } }

public async Task Connect(string? auth, string host, string nameOrAddress, Address clientAddress, Compression compression, bool light)
public async Task Connect(string? auth, string host, string nameOrAddress, ConnectionId connectionId, Compression compression, bool light)
{
var uri = $"{host}/database/subscribe/{nameOrAddress}?client_address={clientAddress}&compression={compression}";
var uri = $"{host}/database/subscribe/{nameOrAddress}?connection_id={connectionId}&compression={compression}";
if (light)
{
uri += "&light=true";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.IdentityConnected
Expand All @@ -56,7 +56,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SetName,
Expand Down Expand Up @@ -85,7 +85,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SetName,
Expand Down Expand Up @@ -114,7 +114,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand All @@ -139,7 +139,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand Down Expand Up @@ -168,7 +168,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SetName,
Expand Down Expand Up @@ -197,7 +197,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SetName,
Expand Down Expand Up @@ -226,7 +226,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand All @@ -251,7 +251,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand Down Expand Up @@ -280,7 +280,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand All @@ -305,7 +305,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand Down Expand Up @@ -334,7 +334,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.IdentityDisconnected
Expand Down Expand Up @@ -366,7 +366,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand All @@ -391,7 +391,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.IdentityConnected
Expand All @@ -56,7 +56,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SetName,
Expand Down Expand Up @@ -85,7 +85,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SetName,
Expand Down Expand Up @@ -114,7 +114,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand All @@ -139,7 +139,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand Down Expand Up @@ -168,7 +168,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SetName,
Expand Down Expand Up @@ -197,7 +197,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SetName,
Expand Down Expand Up @@ -226,7 +226,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand All @@ -251,7 +251,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand Down Expand Up @@ -280,7 +280,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand All @@ -305,7 +305,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand Down Expand Up @@ -334,7 +334,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_2,
CallerAddress: Guid_1,
CallerConnectionId: Guid_1,
EnergyConsumed: {},
Reducer: {
$type: Reducer.IdentityDisconnected
Expand Down Expand Up @@ -366,7 +366,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand All @@ -391,7 +391,7 @@
$type: Status.Committed
},
CallerIdentity: Identity_1,
CallerAddress: Guid_2,
CallerConnectionId: Guid_2,
EnergyConsumed: {},
Reducer: {
$type: Reducer.SendMessage,
Expand Down
6 changes: 3 additions & 3 deletions tests~/SnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static ServerMessage.IdentityToken SampleId(string identity, string toke
{
Identity = Identity.From(Convert.FromBase64String(identity)),
Token = token,
Address = Address.From(Convert.FromBase64String(address)) ?? throw new InvalidDataException("address")
ConnectionId = ConnectionId.From(Convert.FromBase64String(address)) ?? throw new InvalidDataException("address")
});

private static ServerMessage.InitialSubscription SampleLegacyInitialSubscription(
Expand Down Expand Up @@ -176,7 +176,7 @@ ulong hostExecutionDuration
private static ServerMessage.TransactionUpdate SampleTransactionUpdate(
long microsecondsSinceUnixEpoch,
string callerIdentity,
string callerAddress,
string callerConnectionId,
uint requestId,
string reducerName,
ulong energyQuantaUsed,
Expand All @@ -187,7 +187,7 @@ private static ServerMessage.TransactionUpdate SampleTransactionUpdate(
{
Timestamp = new Timestamp { MicrosecondsSinceUnixEpoch = microsecondsSinceUnixEpoch },
CallerIdentity = Identity.From(Convert.FromBase64String(callerIdentity)),
CallerAddress = Address.From(Convert.FromBase64String(callerAddress)) ?? throw new InvalidDataException("callerAddress"),
CallerConnectionId = ConnectionId.From(Convert.FromBase64String(callerConnectionId)) ?? throw new InvalidDataException("callerConnectionId"),
TotalHostExecutionDuration = new TimeDuration(hostExecutionDurationMicros),
EnergyQuantaUsed = new()
{
Expand Down
Loading

0 comments on commit 124a1cb

Please sign in to comment.