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

Merge pull request #129 from geebee/master

Don't only migrate chosen region/protocol entries
Rod Hynes 10 лет назад
Родитель
Сommit
8b79c8a398
3 измененных файлов с 72 добавлено и 79 удалено
  1. 2 1
      ConsoleClient/README.md
  2. 68 29
      ConsoleClient/make.bash
  3. 2 49
      psiphon/migrateDataStore_windows.go

+ 2 - 1
ConsoleClient/README.md

@@ -17,9 +17,10 @@ Note that you may need to use `sudo docker` below, depending on your OS.
     --rm \
     -v $(pwd):/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core \
     psiclient \
-    /bin/bash -c 'cd /go/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ConsoleClient && ./make.bash' \
+    /bin/bash -c 'cd /go/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ConsoleClient && ./make.bash all' \
   ; cd -
   ```
+This command can also be modified by replacing `all` with `windows`, `linux`, or `osx` as the first parameter to `make.bash` (as in `...&& ./make.bash windows`) to only build binaries for the operating system of choice
 
 When that command completes, the compiled binaries will be located in the `bin` directory (`./bin`, and everything under it will likely be owned by root, so be sure to `chown` to an appropriate user) under the current directory. The structure will be:
   ```

+ 68 - 29
ConsoleClient/make.bash

@@ -26,38 +26,77 @@ echo " Build repo: ${BUILDREPO}"
 echo " Build revision: ${BUILDREV}"
 echo ""
 
-echo "Getting project dependencies (via go get)"
-GOOS=linux go get -d -v ./...
-GOOS=windows go get -d -v ./...
-GOOS=darwin go get -d -v ./...
-
 if [ ! -d bin ]; then
   mkdir bin
 fi
 
-echo "Building windows-i686..."
-CC=/usr/bin/i686-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output bin/windows/${EXE_BASENAME}-i686
-# We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
-echo "..No UPX for this build"
-
-echo "Building windows-x86_64..."
-CC=/usr/bin/x86_64-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output bin/windows/${EXE_BASENAME}-x86_64
-# We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
-echo "..No UPX for this build"
-
-echo "Building linux-i686..."
-CFLAGS=-m32 gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output bin/linux/${EXE_BASENAME}-i686
-echo "..UPX packaging output"
-goupx --best bin/linux/${EXE_BASENAME}-i686
-
-echo "Building linux-x86_64..."
-gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output bin/linux/${EXE_BASENAME}-x86_64
-echo "..UPX packaging output"
-goupx --best bin/linux/${EXE_BASENAME}-x86_64
-
-echo "Building darwin-x86_64..."
-CGO_ENABLED=0 gox -verbose -ldflags "$LDFLAGS" -osarch darwin/amd64 -output bin/darwin/${EXE_BASENAME}-x86_64
-# Darwin binaries don't seem to be UPXable when built this way
-echo "..No UPX for this build"
+build_for_windows () {
+  echo "...Getting project dependencies (via go get) for Windows"
+  GOOS=windows go get -d -v ./...
+
+  echo "...Building windows-i686"
+  CC=/usr/bin/i686-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output bin/windows/${EXE_BASENAME}-i686
+  # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
+  echo "....No UPX for this build"
+
+  echo "...Building windows-x86_64"
+  CC=/usr/bin/x86_64-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output bin/windows/${EXE_BASENAME}-x86_64
+  # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
+  echo "....No UPX for this build"
+}
+
+build_for_linux () {
+  echo "Getting project dependencies (via go get) for Linux"
+  GOOS=linux go get -d -v ./...
+
+  echo "...Building linux-i686"
+  CFLAGS=-m32 gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output bin/linux/${EXE_BASENAME}-i686
+  echo "....UPX packaging output"
+  goupx --best bin/linux/${EXE_BASENAME}-i686
+
+  echo "...Building linux-x86_64"
+  gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output bin/linux/${EXE_BASENAME}-x86_64
+  echo "....UPX packaging output"
+  goupx --best bin/linux/${EXE_BASENAME}-x86_64
+}
+
+build_for_osx () {
+  echo "Getting project dependencies (via go get) for OSX"
+  GOOS=darwin go get -d -v ./...
+
+  echo "Building darwin-x86_64..."
+  CGO_ENABLED=0 gox -verbose -ldflags "$LDFLAGS" -osarch darwin/amd64 -output bin/darwin/${EXE_BASENAME}-x86_64
+  # Darwin binaries don't seem to be UPXable when built this way
+  echo "..No UPX for this build"
+}
+
+TARGET=$1
+case $TARGET in
+  windows)
+    echo "..Building for Windows"
+    build_for_windows
+    ;;
+  linux)
+    echo "..Building for Linux"
+    build_for_linux
+    ;;
+  osx)
+    echo "..Building for OSX"
+    build_for_osx
+    ;;
+  all)
+    echo "..Building all"
+    build_for_windows
+    build_for_linux
+    build_for_osx
+    ;;
+  *)
+    echo "..No selection made, building all"
+    build_for_windows
+    build_for_linux
+    build_for_osx
+    ;;
+
+esac
 
 echo "Done"

+ 2 - 49
psiphon/migrateDataStore_windows.go

@@ -116,8 +116,6 @@ func migrateEntries(serverEntries []*ServerEntry, legacyDataStoreFilename string
 // legacyServerEntryIterator is used to iterate over
 // stored server entries in rank order.
 type legacyServerEntryIterator struct {
-	region            string
-	protocol          string
 	shuffleHeadLength int
 	transaction       *sql.Tx
 	cursor            *sql.Rows
@@ -127,8 +125,6 @@ type legacyServerEntryIterator struct {
 func newlegacyServerEntryIterator(config *Config) (iterator *legacyServerEntryIterator, err error) {
 
 	iterator = &legacyServerEntryIterator{
-		region:            config.EgressRegion,
-		protocol:          config.TunnelProtocol,
 		shuffleHeadLength: config.TunnelPoolSize,
 	}
 	err = iterator.Reset()
@@ -187,9 +183,6 @@ func (iterator *legacyServerEntryIterator) Next() (serverEntry *ServerEntry, err
 func (iterator *legacyServerEntryIterator) Reset() error {
 	iterator.Close()
 
-	count := countLegacyServerEntries(iterator.region, iterator.protocol)
-	NoticeCandidateServers(iterator.region, iterator.protocol, count)
-
 	transaction, err := legacyDb.Begin()
 	if err != nil {
 		return ContextError(err)
@@ -201,8 +194,7 @@ func (iterator *legacyServerEntryIterator) Reset() error {
 	// (priority) order, to favor previously successful servers; then the
 	// remaining long tail is shuffled to raise up less recent candidates.
 
-	whereClause, whereParams := makeServerEntryWhereClause(
-		iterator.region, iterator.protocol, nil)
+	whereClause, whereParams := makeServerEntryWhereClause(nil)
 	headLength := iterator.shuffleHeadLength
 	queryFormat := `
 		select data from serverEntry %s
@@ -228,24 +220,9 @@ func (iterator *legacyServerEntryIterator) Reset() error {
 	return nil
 }
 
-func makeServerEntryWhereClause(
-	region, protocol string, excludeIds []string) (whereClause string, whereParams []interface{}) {
+func makeServerEntryWhereClause(excludeIds []string) (whereClause string, whereParams []interface{}) {
 	whereClause = ""
 	whereParams = make([]interface{}, 0)
-	if region != "" {
-		whereClause += " where region = ?"
-		whereParams = append(whereParams, region)
-	}
-	if protocol != "" {
-		if len(whereClause) > 0 {
-			whereClause += " and"
-		} else {
-			whereClause += " where"
-		}
-		whereClause +=
-			" exists (select 1 from serverEntryProtocol where protocol = ? and serverEntryId = serverEntry.id)"
-		whereParams = append(whereParams, protocol)
-	}
 	if len(excludeIds) > 0 {
 		if len(whereClause) > 0 {
 			whereClause += " and"
@@ -264,27 +241,3 @@ func makeServerEntryWhereClause(
 	}
 	return whereClause, whereParams
 }
-
-// countLegacyServerEntries returns a count of stored servers for the specified region and protocol.
-func countLegacyServerEntries(region, protocol string) int {
-	var count int
-	whereClause, whereParams := makeServerEntryWhereClause(region, protocol, nil)
-	query := "select count(*) from serverEntry" + whereClause
-	err := legacyDb.QueryRow(query, whereParams...).Scan(&count)
-
-	if err != nil {
-		NoticeAlert("countLegacyServerEntries failed: %s", err)
-		return 0
-	}
-
-	if region == "" {
-		region = "(any)"
-	}
-	if protocol == "" {
-		protocol = "(any)"
-	}
-	NoticeInfo("servers for region %s and protocol %s: %d",
-		region, protocol, count)
-
-	return count
-}