Skip to content

Commit fe92e3c

Browse files
committed
DataTransport exclude ghost nodes
1 parent 84af52d commit fe92e3c

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

play-services-wearable/core/src/main/java/org/microg/gms/wearable/DataTransport.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.HashMap;
1515
import java.util.List;
1616
import java.util.Map;
17+
import java.util.Set;
1718
import java.util.concurrent.atomic.AtomicBoolean;
1819

1920
public class DataTransport {
@@ -114,7 +115,15 @@ public void sendSyncStart() {
114115
return;
115116
}
116117

117-
Map<String, Long> seqIds = wearable.getNodeDatabase().getAllCurrentSeqIds();
118+
Map<String, Long> allSeqIds = wearable.getNodeDatabase().getAllCurrentSeqIds();
119+
Set<String> activePeers = wearable.getConnectedPeerNodeIds();
120+
Map<String, Long> seqIds = new HashMap<>();
121+
122+
for (Map.Entry<String, Long> e : allSeqIds.entrySet()) {
123+
String src = e.getKey();
124+
if (src != null && (src.equals(localNodeId) || activePeers.contains(src)))
125+
seqIds.put(src, e.getValue());
126+
}
118127

119128
List<SyncTableEntry> table = new ArrayList<>(seqIds.size());
120129
for (Map.Entry<String, Long> e : seqIds.entrySet()) {
@@ -227,18 +236,33 @@ private void startSyncThread(Map<String, Long> remotePeers) {
227236
}
228237

229238
private void runSync(Map<String, Long> remotePeerSeqIds) {
230-
Log.d(TAG, "runSync start: peer=" + peerNodeId);
239+
Set<String> activePeers = wearable.getConnectedPeerNodeIds();
240+
Log.d(TAG, "runSync start: peer=" + peerNodeId
241+
+ " activePeers=" + activePeers.size());
231242
try {
232243
Map<String, Long> localSeqIds = wearable.getNodeDatabase().getAllCurrentSeqIds();
233244
int synced = 0;
234245
int skipped = 0;
246+
int ghostsExcluded = 0;
247+
int echoSkipped = 0;
235248
for (Map.Entry<String, Long> local : localSeqIds.entrySet()) {
236249
if (Thread.currentThread().isInterrupted()) {
237250
Log.d(TAG, "runSync interrupted for peer=" + peerNodeId);
238251
return;
239252
}
240253

241254
String src = local.getKey();
255+
256+
if (src == null || (!src.equals(localNodeId) && !activePeers.contains(src))) {
257+
ghostsExcluded++;
258+
continue;
259+
}
260+
261+
if (src.equals(peerNodeId)){
262+
echoSkipped++;
263+
continue;
264+
}
265+
242266
long peer = remotePeerSeqIds.containsKey(src) ? remotePeerSeqIds.get(src) : -1;
243267
long localMax = local.getValue() != null ? local.getValue() : -1;
244268

@@ -259,6 +283,10 @@ private void runSync(Map<String, Long> remotePeerSeqIds) {
259283
wearable.syncToPeer(peerNodeId, src, peer);
260284
synced++;
261285
}
286+
Log.d(TAG, "runSync: peer=" + peerNodeId
287+
+ "synced=" + synced + " upToDate=" + skipped
288+
+ " ghostsExcluded=" + ghostsExcluded
289+
+ " selfEchoSkipped=" + echoSkipped);
262290
} catch (Exception e) {
263291
Log.w(TAG, "runSync exception for peer=" + peerNodeId, e);
264292
} finally {

play-services-wearable/core/src/main/java/org/microg/gms/wearable/WearableImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,10 @@ public void onDisconnectReceived(WearableConnection connection, Connect connect)
885885
onPeerDisconnected(new NodeParcelable(connect.id, connect.name));
886886
}
887887

888+
public Set<String> getConnectedPeerNodeIds() {
889+
return new HashSet<>(peerTransports.keySet());
890+
}
891+
888892
public List<NodeParcelable> getConnectedNodesParcelableList() {
889893
List<NodeParcelable> nodes = new ArrayList<>();
890894
for (Node connectedNode : connectedNodes) {

0 commit comments

Comments
 (0)