Skip to content

[DX L2] Startup builder for Peer (port/connections/optional security) #18

Description

@Segfaultd

Context

Startup is a multi-call dance. From peerinterface.h:

// :69
virtual StartupResult Startup(unsigned int maxConnections, SocketDescriptor *socketDescriptors,
                              unsigned socketDescriptorCount, int threadPriority=-99999)=0;
// :105
virtual void SetMaximumIncomingConnections(unsigned short numberAllowed)=0;
// :144
virtual ConnectionAttemptResult Connect(const char* host, unsigned short remotePort,
                                         const char *passwordData, int passwordDataLength,
                                         PublicKey *publicKey=0, ...)=0;

Typical server: construct SocketDescriptor (types.h:139), call Startup, check it == RAKNET_STARTED (types.h:38), then SetMaximumIncomingConnections.

Security is optional on masterInitializeSecurity(publicKey, privateKey, bRequireClientKey) (peerinterface.h:80, gated behind LIBCAT_SECURITY) and DisableSecurity() (:84). Connect() takes an optional PublicKey* (types.h:123, default 0 = insecure). This issue does not change the security model — it just offers a tidy place to wire those calls.

Goal

A fluent builder over Peer:

auto server = Peer::server()
    .port(60000)
    .max_connections(32)
    .incoming_password("hunter2")        // optional -> SetIncomingPassword
    .start();                            // -> Startup + SetMaximumIncomingConnections

auto client = Peer::client()
    .max_connections(1)
    .connect("127.0.0.1", 60000)         // -> Startup then Connect
    .start();

start() returns Result<Peer> (or throws — decide in review) carrying the StartupResult / ConnectionAttemptResult on failure.

Where

Add Peer::server() / Peer::client() builder types in Source/include/mafianet/Peer.h (with #16).

Notes

  • Builder owns the SocketDescriptor until start(), so the caller never manages the array/count.
  • Map .reliability_defaults(...) etc. using the scoped enums from [DX L0] Scoped-enum façade for Reliability & Priority #13 if useful.
  • Optional .secure(publicKey, privateKey) may call InitializeSecurity before Startup — keep it opt-in, mirroring master. Do not imply encryption is mandatory.
  • Surface the failure enum clearly; don't collapse it to a bool.

Acceptance criteria

  • Peer::server().port(p).max_connections(n).start() replaces the manual 3-call sequence.
  • Failure path exposes the underlying StartupResult / ConnectionAttemptResult.

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    dxDeveloper experience / public API ergonomicsenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions