You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TIP: Multipeer Replication is currently available for use over IP networks.
14
-
If you are working with a bluetooth network, you will need to use Couchbase Lite's xref::p2psync-websocket.adoc[Active-Passive peer-to-peer].
15
-
16
-
[#introduction]
17
-
== Introduction
18
-
// tag::introduction-full[]
19
-
// tag::introduction[]
20
-
Couchbase Lite's Peer-to-Peer synchronization solution offers secure storage and bidirectional data synchronization between edge devices without needing a centralized cloud-based control point.
21
-
22
-
23
-
// *** advantages ***
24
-
25
-
Multipeer Replicator for small mesh topologies offers autodiscovery for wifi-based networks.
26
-
Multipeer Sync thus requires less management and less code than using active-passive peer-to-peer sync, and also manages peer discovery for you.
27
-
28
-
// Bluetooth - not yet
29
-
30
-
[TIP]
31
-
.Bluetooth networking
32
-
====
33
-
If you are working over a bluetooth network, then take a look at Couchbase Lite's Active-Passive Peer-to-Peer synchronization.
34
-
====
35
-
36
-
37
-
// end::introduction[]
38
-
// end::introduction-full[]
39
-
40
-
41
-
42
-
== Prerequisites
43
-
44
-
=== Transport and Peer Discovery Protocol
45
-
46
-
MultipeerReplicator supports Wi-Fi transport, using DNS-SD (also known as Bonjour) for peer discovery.
47
-
Peers must be connected to the same Wi-Fi network to discover and establish connections with one another.
48
-
49
-
=== Supported Platforms
50
-
51
-
For Android, the minimum API level is API 35, based on the availability of required DNS-SD features for peer discovery and mesh network construction—such as support for subtypes, and the ability to publish and subscribe to service information.
52
-
53
-
54
-
== Overview
55
-
56
-
The MultipeerReplicator automatically advertises its presence, discovers other peers,
57
-
and establishes connections for data replication with peers that share the same group identifier defined by the application.
58
-
59
-
To maintain optimal connectivity, efficient data transport, and balanced workloads, the MultipeerReplicator forms a dynamic mesh network among peers in the same group.
60
-
It avoids redundant direct connections, evenly distributes connections across peers, and optimizes communication paths.
61
-
The mesh network continuously adapts as peers join or leave.
62
-
63
-
====
64
-
*TODO* Mesh Diagram
65
-
====
66
-
67
-
68
-
== Configuration
69
-
70
-
.Configuration for creating a MultipeerReplicator
71
-
[source,java]
72
-
----
73
-
public struct MultipeerReplicatorConfiguration {
74
-
/// Identifier for discovering and connecting peers.
75
-
public let peerGroupID: String
76
-
77
-
/// Peer identity.
78
-
/// @Note The identity’s certificate must be both server and client certificate.
79
-
public let identity: TLSIdentity
80
-
81
-
82
-
/// Peer authenticator.
83
-
public let authenticator: MultipeerAuthenticator
84
-
85
-
86
-
/// Collections to replicate.
87
-
public let collections: [MultipeerCollectionConfiguration]
88
-
89
-
90
-
/// Initialize the configuration with a peer group identifier, identity,
91
-
/// authenticator and collections.
92
-
public init(peerGroupID: String,
93
-
identity: TLSIdentity,
94
-
authenticator: MultipeerCertificateAuthenticator,
95
-
collections: [MultipeerCollectionConfiguration])
96
-
}
97
-
----
98
-
99
-
100
-
101
-
102
-
103
-
TIP: In version 3.3.0, the recommended maximum number of peers in a mesh network is approximately 15.
104
-
105
-
=== Life Cycle
106
-
107
-
Starting and stopping a peer-to-peer connection...
108
-
109
-
110
-
=== Listening for Changes
111
-
112
-
Event types...
113
-
114
-
115
-
`PeerDocumentReplication`
116
-
117
-
118
-
== Example Use
119
-
120
-
Here we will show how to instansiate a `MultipeerReplicatorConfiguration` configuration with self-signed certificates, and connect it to an example collection.
121
-
122
-
[source,kotlin]
123
-
----
124
-
// Code sample
125
-
----
126
-
127
-
128
-
129
-
=== MultipeerCollectionConfiguration
130
-
131
-
`MultipeerCollectionConfiguration` specifies a collection and its associated settings.
132
-
This includes a conflict resolver and replication filters.
133
-
A list of these configurations is required to define which collections will be replicated within the peer group network.
134
-
135
-
136
-
[source,kotlin]
137
-
----
138
-
/// Type Alias for Multipeer Replication Filter Function.
/// Defines collection for replication including optional filters and
149
-
/// custom conflict resolver.
150
-
public struct MultipeerCollectionConfiguration {
151
-
/// The collection.
152
-
public let collection: Collection
153
-
154
-
/// Document IDs filter.
155
-
public var documentIDs: Array<String>?
156
-
157
-
/// Push filter.
158
-
public var pushFilter: MultipeerReplicationFilter?
159
-
160
-
/// Pull filter.
161
-
public var pullFilter: MultipeerReplicationFilter?
162
-
163
-
164
-
/// Custom conflict resolver.
165
-
public var conflictResolver: MultipeerConflictResolver?
166
-
167
-
168
-
/// Initialize with a collection.
169
-
public init(collection: Collection)
170
-
}
171
-
----
172
-
173
-
174
-
=== Authenticator
175
-
176
-
`MultipeerCertificateAuthenticator` *TODO*
177
-
178
-
179
-
=== Peer Info
180
-
181
-
`PeerInfo` provides information about the peer, including a peer unique identifier, the peer certificate, online status, replicator status, and its current `neighborPeers`.
182
-
183
-
184
-
[source,kotlin]
185
-
----
186
-
//
187
-
----
188
-
189
-
190
-
=== Self-signed Certs
191
-
192
-
.Creating a self-signed certificate that can be used as both client and server cert
193
-
[source,kotlin]
194
-
----
195
-
/// Extended Key Usage for which the certified public key may be used.
196
-
public struct KeyUsages: OptionSet {
197
-
/// For Server Authentication
198
-
public static let serverAuth = 0x40
199
-
200
-
/// For Client Authentication
201
-
public static let clientAuth = 0x80
202
-
}
203
-
204
-
/// TLS Identity
205
-
public class TLSIdentity {
206
-
/// Create a TLS identity from private key and certificate data.
207
-
///
208
-
/// The private key and certificate data must be either in PEM or DER format.
209
-
/// This method can be used to create an issuer identity for signing
210
-
/// a certificate when generating a new TLS identity.
211
-
public static func createIdentity(privateKey: Data,
212
-
certificate: Data) throws -> TLSIdentity
213
-
214
-
215
-
/// Generate a TLS identity, either self-signed or signed by an issuer identity.
216
-
///
217
-
/// The `attributes` must include a common name (CN); otherwise an error
218
-
/// will be thrown.
219
-
///
220
-
/// If no the expiration date is specified, the default validity of one year
221
-
/// will be applied.
222
-
///
223
-
/// The optional issuer identity may be specified to sign the certificate.
224
-
/// The issuer identity can be created using
225
-
/// `createIdentity(privateKeyData:certificateData:)`. If no issuer is specified,
226
-
/// the certificate will be self-signed.
227
-
///
228
-
/// If a `label` is provided, the identity will be stored in the
229
-
/// platform’s secure key storage under that label.
230
-
public static func createIdentity(keyUsages: KeyUsages,
0 commit comments