PeerConfig
Configuration options for initializing a peer. Use the Builder pattern to create an instance with safe defaults.
Recommended defaults
In production, we recommend enabling encryption, using an app-scoped identifier, and setting conservative connection limits. See Security Best Practices and Performance Optimization.
Builder Methods
setAppId(appId)
Sets the unique application identifier. This isolates your peer network from other applications.
setAppId(appId: String): BuilderenableEncryption(enabled)
Enables or disables end-to-end encryption for all connections.
enableEncryption(enabled: Boolean): BuildersetPort(port)
Sets the listening port for incoming connections. Defaults to a random available port.
setPort(port: Int): BuildersetMaxPeers(maxPeers)
Sets the maximum number of concurrent peer connections. Use this to cap CPU/bandwidth usage on constrained devices.
setMaxPeers(maxPeers: Int): Builderbuild()
Builds and returns the PeerConfig instance.
build(): PeerConfigExamples
Secure default config
val config = PeerConfig.Builder()
.setAppId("your-app-id")
.enableEncryption(true)
.setMaxPeers(24)
.build()
Mobile-friendly config
val config = PeerConfig.Builder()
.setAppId("your-app-id")
.enableEncryption(true)
.setMaxPeers(12)
.build()
// Tip: pair with platform guidance:
// Android: background execution + keepalive policy
// iOS: background modes and wake constraints