Просмотр исходного кода

Add mechanism to trigger clients to clear their SLOKs

Rod Hynes 9 лет назад
Родитель
Сommit
68cebee9a7
3 измененных файлов с 24 добавлено и 1 удалено
  1. 2 1
      psiphon/common/protocol/protocol.go
  2. 18 0
      psiphon/dataStore.go
  3. 4 0
      psiphon/serverApi.go

+ 2 - 1
psiphon/common/protocol/protocol.go

@@ -102,7 +102,8 @@ type ConnectedResponse struct {
 }
 
 type OSLRequest struct {
-	SeedPayload *osl.SeedPayload `json:"seed_payload"`
+	ClearLocalSLOKs bool             `json:"clear_local_sloks"`
+	SeedPayload     *osl.SeedPayload `json:"seed_payload"`
 }
 
 type SSHPasswordPayload struct {

+ 18 - 0
psiphon/dataStore.go

@@ -999,6 +999,24 @@ func resetAllTunnelStatsToUnreported() error {
 	return nil
 }
 
+// DeleteSLOKs deletes all SLOK records.
+func DeleteSLOKs() error {
+	checkInitDataStore()
+
+	err := singleton.db.Update(func(tx *bolt.Tx) error {
+		bucket := tx.Bucket([]byte(slokBucket))
+		return bucket.ForEach(
+			func(id, _ []byte) error {
+				return bucket.Delete(id)
+			})
+	})
+
+	if err != nil {
+		return common.ContextError(err)
+	}
+	return nil
+}
+
 // SetSLOK stores a SLOK key, referenced by its ID. The bool
 // return value indicates whether the SLOK was already stored.
 func SetSLOK(id, key []byte) (bool, error) {

+ 4 - 0
psiphon/serverApi.go

@@ -924,6 +924,10 @@ func HandleOSLRequest(tunnel *Tunnel, payload []byte) error {
 		return common.ContextError(err)
 	}
 
+	if oslRequest.ClearLocalSLOKs {
+		DeleteSLOKs()
+	}
+
 	for _, slok := range oslRequest.SeedPayload.SLOKs {
 		duplicate, err := SetSLOK(slok.ID, slok.Key)
 		if err != nil {