Skip to content

Commit

Permalink
Protocol: support specifying the machineID through ClientSetupResult. (
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds committed Jan 19, 2024
1 parent 2c9eb4c commit c7eb055
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Tmds.DBus.Protocol/ClientConnectionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ protected internal virtual ValueTask<ClientSetupResult> SetupAsync(CancellationT
new ClientSetupResult(_address)
{
SupportsFdPassing = true,
UserId = DBusEnvironment.UserId
UserId = DBusEnvironment.UserId,
MachineId = DBusEnvironment.MachineId
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/Tmds.DBus.Protocol/ClientSetupResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public ClientSetupResult(string address)

public string? UserId { get; set; }

public string? MachineId { get; set; }

public bool SupportsFdPassing { get; set; }
}
4 changes: 2 additions & 2 deletions src/Tmds.DBus.Protocol/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Connection(ConnectionOptions connectionOptions)
// For tests.
internal void Connect(IMessageStream stream)
{
_connection = new DBusConnection(this);
_connection = new DBusConnection(this, DBusEnvironment.MachineId);
_connection.Connect(stream);
_state = ConnectionState.Connected;
}
Expand Down Expand Up @@ -98,7 +98,7 @@ private async Task<DBusConnection> DoConnectAsync()
{
_connectCts = new();
_setupResult = await _connectionOptions.SetupAsync(_connectCts.Token).ConfigureAwait(false);
connection = _connection = new DBusConnection(this);
connection = _connection = new DBusConnection(this, _setupResult.MachineId ?? DBusEnvironment.MachineId);

await connection.ConnectAsync(_setupResult.ConnectionAddress, _setupResult.UserId, _setupResult.SupportsFdPassing, _connectCts.Token).ConfigureAwait(false);

Expand Down
6 changes: 4 additions & 2 deletions src/Tmds.DBus.Protocol/DBusConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void Invoke(Exception? exception, Message message)
private readonly Dictionary<string, MatchMaker> _matchMakers;
private readonly List<Observer> _matchedObservers;
private readonly Dictionary<string, IMethodHandler> _pathHandlers;
private readonly string? _machineId;

private IMessageStream? _messageStream;
private ConnectionState _state;
Expand All @@ -130,14 +131,15 @@ public Exception DisconnectReason

public bool RemoteIsBus => _localName is not null;

public DBusConnection(Connection parent)
public DBusConnection(Connection parent, string machineId)
{
_parentConnection = parent;
_connectCts = new();
_pendingCalls = new();
_matchMakers = new();
_matchedObservers = new();
_pathHandlers = new();
_machineId = machineId;
}

// For tests.
Expand Down Expand Up @@ -1275,7 +1277,7 @@ ValueTask IMethodHandler.HandleMethodAsync(MethodContext context)
else if (context.Request.Member.SequenceEqual("GetMachineId"u8))
{
using var writer = context.CreateReplyWriter("s");
writer.WriteString(DBusEnvironment.MachineId);
writer.WriteString(_machineId);

Check warning on line 1280 in src/Tmds.DBus.Protocol/DBusConnection.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'value' in 'void MessageWriter.WriteString(string value)'.

Check warning on line 1280 in src/Tmds.DBus.Protocol/DBusConnection.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'value' in 'void MessageWriter.WriteString(string value)'.

Check warning on line 1280 in src/Tmds.DBus.Protocol/DBusConnection.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'value' in 'void MessageWriter.WriteString(string value)'.

Check warning on line 1280 in src/Tmds.DBus.Protocol/DBusConnection.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'value' in 'void MessageWriter.WriteString(string value)'.
context.Reply(writer.CreateMessage());
}
}
Expand Down

0 comments on commit c7eb055

Please sign in to comment.