Browse Source

Merge remote-tracking branch 'rod/master'

Adam Pritchard 11 years ago
parent
commit
62a53ad2d0
1 changed files with 12 additions and 5 deletions
  1. 12 5
      psiphon/dataStore.go

+ 12 - 5
psiphon/dataStore.go

@@ -50,9 +50,10 @@ func initDataStore() {
              data blob not null);
 	    create table if not exists serverEntryProtocol
 	        (serverEntryId text not null,
-	         protocol text not null);
+	         protocol text not null,
+	         primary key (serverEntryId, protocol));
         create table if not exists keyValue
-            (key text not null,
+            (key text not null primary key,
              value text not null);
 		pragma journal_mode=WAL;
         `
@@ -150,6 +151,12 @@ func StoreServerEntry(serverEntry *ServerEntry, replaceIfExists bool) error {
             insert or replace into serverEntry (id, rank, region, data)
             values (?, (select coalesce(max(rank)-1, 0) from serverEntry), ?, ?);
             `, serverEntry.IpAddress, serverEntry.Region, data)
+		if err != nil {
+			return err
+		}
+		_, err = transaction.Exec(`
+            delete from serverEntryProtocol where serverEntryId = ?;
+            `, serverEntry.IpAddress)
 		if err != nil {
 			return err
 		}
@@ -159,9 +166,9 @@ func StoreServerEntry(serverEntry *ServerEntry, replaceIfExists bool) error {
 			requiredCapability := strings.TrimSuffix(protocol, "-OSSH")
 			if Contains(serverEntry.Capabilities, requiredCapability) {
 				_, err = transaction.Exec(`
-		            insert or ignore into serverEntryProtocol (serverEntryId, protocol)
-		            values (?, ?);
-		            `, serverEntry.IpAddress, protocol)
+                    insert into serverEntryProtocol (serverEntryId, protocol)
+                    values (?, ?);
+                    `, serverEntry.IpAddress, protocol)
 				if err != nil {
 					return err
 				}