Skip to content

Commit

Permalink
Merge branch 'master' into staging-server
Browse files Browse the repository at this point in the history
  • Loading branch information
rod-hynes committed Jun 3, 2024
2 parents e60f90c + 1191a6b commit 5777cd6
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 8 deletions.
8 changes: 8 additions & 0 deletions MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ default public void onActiveAuthorizationIDs(List<String> authorizations) {}
default public void onTrafficRateLimits(long upstreamBytesPerSecond, long downstreamBytesPerSecond) {}
default public void onApplicationParameters(Object parameters) {}
default public void onServerAlert(String reason, String subject, List<String> actionURLs) {}
/**
* Called when tunnel-core reports connected server region information.
* @param region The server region received.
*/
default public void onConnectedServerRegion(String region) {}
default public void onExiting() {}
}

Expand Down Expand Up @@ -1079,6 +1084,9 @@ private void handlePsiphonNotice(String noticeJSON) {
enableUdpGwKeepalive();
}
}
// Also report the tunnel's egress region to the host service
mHostService.onConnectedServerRegion(
notice.getJSONObject("data").getString("serverRegion"));
} else if (noticeType.equals("ApplicationParameters")) {
mHostService.onApplicationParameters(
notice.getJSONObject("data").get("parameters"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
// always specify exact library version in your real project to avoid non-deterministic builds
implementation 'ca.psiphon:psiphontunnel:2.+'

// For the latest version compile the library from source, see MobileLibrary/Android/README.md
// in the Psiphon-Labs/psiphon-tunnel-core repository, copy the ca.psiphon.aar artifact to
// the libs folder under the app module and replace the above line
// (e.g. replace implementation 'ca.psiphon:psiphontunnel:2.+')
// with the following line:
// implementation files('libs/ca.psiphon.aar')
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Licensed under Creative Commons Zero (CC0).
import android.content.Context;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
Expand Down Expand Up @@ -61,6 +63,7 @@ Licensed under Creative Commons Zero (CC0).
public class MainActivity extends AppCompatActivity
implements PsiphonTunnel.HostService {

private static final String TAG = "TunneledWebView";
private ListView mListView;
private WebView mWebView;

Expand Down Expand Up @@ -152,6 +155,7 @@ private void logMessage(final String message) {
public void run() {
mLogMessages.add(message);
mListView.setSelection(mLogMessages.getCount() - 1);
Log.d(TAG, "logMessage: " + message);
}
});
}
Expand Down Expand Up @@ -249,6 +253,11 @@ public void onConnected() {
loadWebView();
}

@Override
public void onConnectedServerRegion(String region) {
logMessage("connected server region: " + region);
}

@Override
public void onHomepage(String url) {
logMessage("home page: " + url);
Expand Down
6 changes: 6 additions & 0 deletions MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ WWAN or vice versa or VPN state changed
*/
- (void)onApplicationParameters:(NSDictionary * _Nonnull)parameters;


/*!
Called when tunnel-core reports connected server region information
@param region The server region received.
*/
- (void)onConnectedServerRegion:(NSString * _Nonnull)region;
@end

/*!
Expand Down
12 changes: 12 additions & 0 deletions MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,18 @@ - (void)handlePsiphonNotice:(NSString * _Nonnull)noticeJSON {
});
}
}
else if ([noticeType isEqualToString:@"ActiveTunnel"]) {
id region = [notice valueForKeyPath:@"data.serverRegion"];
if (![region isKindOfClass:[NSString class]]) {
[self logMessage:[NSString stringWithFormat: @"ActiveTunnel notice missing data.serverRegion: %@", noticeJSON]];
return;
}
if ([self.tunneledAppDelegate respondsToSelector:@selector(onConnectedServerRegion:)]) {
dispatch_sync(self->callbackQueue, ^{
[self.tunneledAppDelegate onConnectedServerRegion:region];
});
}
}
else if ([noticeType isEqualToString:@"InternalError"]) {
internalError = TRUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,8 @@ extension AppDelegate: TunneledAppDelegate {
self.httpProxyPort = port
}
}

func onConnectedServerRegion(_ region: String) {
NSLog("onConnectedServerRegion(%@)", region)
}
}
3 changes: 2 additions & 1 deletion psiphon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,8 @@ loop:
NoticeActiveTunnel(
connectedTunnel.dialParams.ServerEntry.GetDiagnosticID(),
connectedTunnel.dialParams.TunnelProtocol,
connectedTunnel.dialParams.ServerEntry.SupportsSSHAPIRequests())
connectedTunnel.dialParams.ServerEntry.SupportsSSHAPIRequests(),
connectedTunnel.dialParams.ServerEntry.Region)

if isFirstTunnel {

Expand Down
5 changes: 3 additions & 2 deletions psiphon/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,12 +678,13 @@ func NoticeRequestedTactics(dialParams *DialParameters) {
}

// NoticeActiveTunnel is a successful connection that is used as an active tunnel for port forwarding
func NoticeActiveTunnel(diagnosticID, protocol string, isTCS bool) {
func NoticeActiveTunnel(diagnosticID, protocol string, isTCS bool, serverRegion string) {
singletonNoticeLogger.outputNotice(
"ActiveTunnel", noticeIsDiagnostic,
"diagnosticID", diagnosticID,
"protocol", protocol,
"isTCS", isTCS)
"isTCS", isTCS,
"serverRegion", serverRegion)
}

// NoticeSocksProxyPortInUse is a failure to use the configured LocalSocksProxyPort
Expand Down
5 changes: 3 additions & 2 deletions psiphon/server/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ func (d *Discovery) reload(reloadedTactics bool) error {
// Initialize and set underlying discovery component. Replaces old
// component if discovery is already initialized.

oldDiscovery := d.discovery

discovery := discovery.MakeDiscovery(
d.support.PsinetDatabase.GetDiscoveryServers(),
discoveryStrategy)
Expand All @@ -120,6 +118,7 @@ func (d *Discovery) reload(reloadedTactics bool) error {

d.Lock()

oldDiscovery := d.discovery
d.discovery = discovery
d.currentStrategy = strategy

Expand All @@ -143,6 +142,8 @@ func (d *Discovery) reload(reloadedTactics bool) error {

// Stop stops discovery and cleans up underlying resources.
func (d *Discovery) Stop() {
d.Lock()
defer d.Unlock()
d.discovery.Stop()
}

Expand Down
3 changes: 2 additions & 1 deletion psiphon/server/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func (d *Discovery) Start() {
// Note: servers with a discovery date range in the past are not
// removed from d.all in case the wall clock has drifted;
// otherwise, we risk removing them prematurely.
servers, nextUpdate := discoverableServers(d.all, d.clk)
var servers []*psinet.DiscoveryServer
servers, nextUpdate = discoverableServers(d.all, d.clk)

// Update the set of discoverable servers.
d.strategy.serversChanged(servers)
Expand Down
4 changes: 2 additions & 2 deletions psiphon/server/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func runDiscoveryTest(tt *discoveryTest, now time.Time) error {
discovery.Start()

for _, check := range tt.checks {
time.Sleep(1 * time.Second) // let async code complete
time.Sleep(10 * time.Millisecond) // let async code complete
clk.SetNow(check.t)
time.Sleep(1 * time.Second) // let async code complete
time.Sleep(10 * time.Millisecond) // let async code complete
discovered := discovery.SelectServers(net.IP{})
discoveredIPs := make([]string, len(discovered))
for i := range discovered {
Expand Down

0 comments on commit 5777cd6

Please sign in to comment.