Check the Sync args for bad peer device IDs.
Change-Id: I8e070ac2262cbe902671643ca243c3b3b7981a9b
diff --git a/runtimes/google/vsync/initiator.go b/runtimes/google/vsync/initiator.go
index a9a30f4..1257d5a 100644
--- a/runtimes/google/vsync/initiator.go
+++ b/runtimes/google/vsync/initiator.go
@@ -85,12 +85,24 @@
}
// Bootstrap my peer list.
- if peerEndpoints != "" {
+ if peerEndpoints != "" || peerDeviceIDs != "" {
i.neighbors = strings.Split(peerEndpoints, ",")
i.neighborIDs = strings.Split(peerDeviceIDs, ",")
- }
- if len(i.neighbors) != len(i.neighborIDs) {
- vlog.Fatalf("newInitiator: Mismatch between number of endpoints and IDs")
+ if len(i.neighbors) != len(i.neighborIDs) {
+ vlog.Fatalf("newInitiator: Mismatch between number of endpoints and IDs")
+ }
+
+ // Neighbor IDs must be distinct and different from my ID.
+ neighborIDs := make(map[string]struct{})
+ for _, nID := range i.neighborIDs {
+ if DeviceID(nID) == i.syncd.id {
+ vlog.Fatalf("newInitiator: neighboor ID %v cannot be the same as my ID %v", nID, i.syncd.id)
+ }
+ if _, ok := neighborIDs[nID]; ok {
+ vlog.Fatalf("newInitiator: neighboor ID %v is duplicated", nID)
+ }
+ neighborIDs[nID] = struct{}{}
+ }
}
// Override the default peerSyncInterval value if syncTick is specified.
diff --git a/runtimes/google/vsync/vsyncd.go b/runtimes/google/vsync/vsyncd.go
index a70de6e..fdd25b8 100644
--- a/runtimes/google/vsync/vsyncd.go
+++ b/runtimes/google/vsync/vsyncd.go
@@ -8,6 +8,7 @@
// log records in response to a GetDeltas request, it replays those
// log records to get in sync with the sender.
import (
+ "fmt"
"sync"
"time"
@@ -161,6 +162,12 @@
func (s *syncd) GetDeltas(_ ipc.ServerContext, In GenVector, ClientID DeviceID, Stream SyncServiceGetDeltasStream) (GenVector, error) {
vlog.VI(1).Infof("GetDeltas:: Received vector %v from client %s", In, ClientID)
+ // Handle misconfiguration: the client cannot have the same ID as me.
+ if ClientID == s.id {
+ vlog.VI(1).Infof("GetDeltas:: impostor alert: client ID %s is the same as mine %s", ClientID, s.id)
+ return GenVector{}, fmt.Errorf("impostor: you cannot be %s, for I am %s", ClientID, s.id)
+ }
+
if err := s.updateDeviceInfo(ClientID, In); err != nil {
vlog.Fatalf("GetDeltas:: updateDeviceInfo failed with err %v", err)
}