Skip to content

Commit

Permalink
Merge pull request #20 from camalot/feature/reverse-forward
Browse files Browse the repository at this point in the history
manual merge of change submitted in PR #19
  • Loading branch information
camalot committed May 18, 2016
2 parents d1791a5 + aa010e5 commit a8b49d9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
8 changes: 5 additions & 3 deletions .appveyor/appveyor.before-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ try {
Import-Module "$env:APPVEYOR_BUILD_FOLDER\.appveyor\modules\Import-PfxCertificate.psm1";
Import-Module "$env:APPVEYOR_BUILD_FOLDER\.appveyor\modules\Set-BuildVersion.psm1";


Import-PfxCertificate -pfx "$env:APPVEYOR_BUILD_FOLDER\Shared\madb.pfx" -password ((Get-Item Env:\MADB_PFX_KEY).Value) -containerName ((Get-Item Env:\VS_PFX_KEY).Value);

if( (Test-Path -Path 'Env:\VS_PFX_KEY') -and (Test-Path -Path Env:\MADB_PFX_KEY) ) {
Import-PfxCertificate -pfx "$env:APPVEYOR_BUILD_FOLDER\Shared\madb.pfx" -password ((Get-Item Env:\MADB_PFX_KEY).Value) -containerName ((Get-Item Env:\VS_PFX_KEY).Value);
} else {
"VS_PFX_KEY and MAD_PFX_KEY are missing; skipping PFX Certificate import." | Write-Warning;
}
$env:CI_BUILD_DATE = ((Get-Date).ToUniversalTime().ToString("MM-dd-yyyy"));
$env:CI_BUILD_TIME = ((Get-Date).ToUniversalTime().ToString("hh:mm:ss"));

Expand Down
2 changes: 1 addition & 1 deletion Madb.Site/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<package id="Antlr" version="3.4.1.9004" targetFramework="net451" />
<package id="bootstrap" version="3.2.0" targetFramework="net451" />
<package id="Camalot.Common" version="1.0.5937.17275" targetFramework="net451" />
<package id="Camalot.Common.Mvc5" version="5.0.5230.247" targetFramework="net451" />
<package id="Camalot.Common.Mvc5" version="5.0.5937.17276" targetFramework="net451" />
<package id="font-awesome" version="4.1.0" targetFramework="net451" />
<package id="jQuery" version="2.1.1" targetFramework="net451" />
<package id="jQuery.Validation" version="1.13.0" targetFramework="net451" />
Expand Down
45 changes: 45 additions & 0 deletions Managed.AndroidDebugBridge/AdbHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,51 @@ public bool CreateForward ( IPEndPoint adbSockAddr, Device device, int localPort
return true;
}

/// <summary>
/// Creates the reverse forward.
/// </summary>
/// <param name="adbSockAddr">The adb sock addr.</param>
/// <param name="device">The device.</param>
/// <param name="remotePort">The remote port.</param>
/// <param name="localPort">The local port.</param>
/// <returns></returns>
/// <exception cref="Managed.Adb.Exceptions.AdbException">
/// failed to submit the forward command.
/// or
/// Device rejected command: + resp.Message
/// </exception>
public bool CreateReverseForward ( IPEndPoint adbSockAddr, Device device, int remotePort, int localPort ) {

Socket adbChan = new Socket ( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
try {
adbChan.Connect ( adbSockAddr );
adbChan.Blocking = true;

// if the device is not -1, then we first tell adb we're looking to talk
// to a specific device
SetDevice ( adbChan, device );

byte[] request = FormAdbRequest ( String.Format ( "reverse:forward:tcp:{0};tcp:{1}", //$NON-NLS-1$
remotePort, localPort ) );

if ( !Write ( adbChan, request ) ) {
throw new AdbException ( "failed to submit the reverse forward command." );
}

AdbResponse resp = ReadAdbResponse ( adbChan, false /* readDiagString */);
if ( !resp.IOSuccess || !resp.Okay ) {
throw new AdbException ( "Device rejected command: " + resp.Message );
}
} finally {
if ( adbChan != null ) {
adbChan.Close ( );
}
}

return true;
}


/// <summary>
/// Lists the forward.
/// </summary>
Expand Down
19 changes: 18 additions & 1 deletion Managed.AndroidDebugBridge/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,24 @@ public bool CreateForward ( int localPort, int remotePort ) {
return false;
}
}



/// <summary>
/// Creates a reverse port forwarding between a local and a remote port.
/// </summary>
/// <param name="remotePort">the remote port to forward</param>
/// <param name="localPort">the local port.</param>
/// <returns><code>true</code> if success.</returns>
public bool CreateReverseForward ( int remotePort, int localPort )
{
try {
return AdbHelper.Instance.CreateReverseForward(AndroidDebugBridge.SocketAddress, this, remotePort, localPort);
} catch(IOException e) {
Log.w("ddms", e);
return false;
}
}

/// <summary>
/// Removes a port forwarding between a local and a remote port.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Managed.AndroidDebugBridge/IDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ public interface IDevice {
/// <returns><code>true</code> if success.</returns>
bool CreateForward(int localPort, int remotePort);

/// <summary>
/// Creates a reverse port forwarding between a local and a remote port.
/// </summary>
/// <param name="remotePort">the remote port to forward</param>
/// <param name="localPort">the local port.</param>
/// <returns><code>true</code> if success.</returns>
bool CreateReverseForward ( int remotePort, int localPort );

/// <summary>
/// Removes a port forwarding between a local and a remote port.
/// </summary>
Expand Down

0 comments on commit a8b49d9

Please sign in to comment.