syncbase: Increase connection timeout.

The current syncbase connection timeout is 2 seconds. This causes
issues in our offline sync scenario because bt classic connections
take 3 seconds to get established.

Change-Id: I77943f22bca9704b88af5ab396f39872035841c4
diff --git a/services/syncbase/vsync/parameters.go b/services/syncbase/vsync/parameters.go
index c5af557..4b20d4d 100644
--- a/services/syncbase/vsync/parameters.go
+++ b/services/syncbase/vsync/parameters.go
@@ -16,9 +16,16 @@
 	// connections to peers.
 	channelTimeout = 2 * time.Second
 
-	// peerConnectionTimeout is the time duration we wait for a connection to be
-	// established with a peer.
-	peerConnectionTimeout = 2 * time.Second
+	// TODO(suharshs): Make the timeouts below more dynamic based on network. (i.e.
+	// bt vs tcp). Currently bt connection establishment takes ~3 seconds, so
+	// neighborhood connections get more time than cloud connections.
+	// neighborConnectionTimeout is the time duration we wait for a connection to be
+	// established with a peer discovered from the neighborhood.
+	neighborConnectionTimeout = 5 * time.Second
+
+	// cloudConnectionTimeout is the duration we wait for a connection to be
+	// established with a cloud peer.
+	cloudConnectionTimeout = 2 * time.Second
 
 	// syncConnectionTimeout is the duration we wait for syncing to begin with a
 	// peer. A value of 0 means we will only use connections that exist in our
diff --git a/services/syncbase/vsync/peer_manager.go b/services/syncbase/vsync/peer_manager.go
index d48bb24..b8c695e 100644
--- a/services/syncbase/vsync/peer_manager.go
+++ b/services/syncbase/vsync/peer_manager.go
@@ -456,7 +456,7 @@
 
 	vlog.VI(4).Infof("sync: pingPeers: sending names %v", names)
 
-	res, err := ping.PingInParallel(ctx, names, peerConnectionTimeout, channelTimeout)
+	res, err := ping.PingInParallel(ctx, names, neighborConnectionTimeout, channelTimeout)
 	if err != nil {
 		return nil
 	}
diff --git a/services/syncbase/vsync/syncgroup.go b/services/syncbase/vsync/syncgroup.go
index 241672a..32f07c7 100644
--- a/services/syncbase/vsync/syncgroup.go
+++ b/services/syncbase/vsync/syncgroup.go
@@ -1252,7 +1252,7 @@
 func (sd *syncDatabase) joinSyncgroupAtAdmin(ctxIn *context.T, call rpc.ServerCall, dbId, sgId wire.Id, remoteSyncbaseName string, expectedSyncbaseBlessings []string, localSyncbaseName string, myInfo wire.SyncgroupMemberInfo) (interfaces.Syncgroup, string, interfaces.GenVector, error) {
 	vlog.VI(2).Infof("sync: joinSyncgroupAtAdmin: begin, dbId %v, sgId %v, remoteSyncbaseName %v", dbId, sgId, remoteSyncbaseName)
 
-	ctx, cancel := context.WithTimeout(ctxIn, peerConnectionTimeout)
+	ctx, cancel := context.WithTimeout(ctxIn, cloudConnectionTimeout)
 	c := interfaces.SyncClient(naming.Join(remoteSyncbaseName, common.SyncbaseSuffix))
 	sg, vers, gv, err := c.JoinSyncgroupAtAdmin(ctx, dbId, sgId, localSyncbaseName, myInfo)
 	cancel()
@@ -1275,7 +1275,7 @@
 	neighbors := ss.filterSyncgroupAdmins(dbId, sgId)
 	for _, svc := range neighbors {
 		for _, addr := range svc.Addresses {
-			ctx, cancel := context.WithTimeout(ctxIn, peerConnectionTimeout)
+			ctx, cancel := context.WithTimeout(ctxIn, neighborConnectionTimeout)
 			// TODO(fredq): check that the service at addr has the expectedSyncbaseBlessings.
 			c := interfaces.SyncClient(naming.Join(addr, common.SyncbaseSuffix))
 			sg, vers, gv, err := c.JoinSyncgroupAtAdmin(ctx, dbId, sgId, localSyncbaseName, myInfo)