Skip to content

Commit

Permalink
UPnP support (#144)
Browse files Browse the repository at this point in the history
* Adds initial implementation for UPnP.

* Updates build instructions.

* Returns string representation of UPnP errors and fixes compilation of FSCP samples.

* Throws error if UPnP IGD is not supported.

* Removes vim backup file.

* Adds libminiupnpc dependency for Linux/macOS in Travis CI and in Dockerfile.

* Adds Windows 'attendee' target to build miniupnpc.

* Updates build documentation to add cmake requirement (to generate vcxproj for miniupnpc dependency).

* Adds support for recent miniupnpc library (API change).

* Changes Windows vcxproj to build FreeLAN with libminiupnpcplus.

* Removes sample binary.

* Fixes Dockerfile dependency for libminiupnpc.

* Adds libminiupnpc dependency for valgrind provisioning.

* Uses miniupnpcd.lib link for Windows debug build.

* Adds UPnP option in configuration file.

* Adds some logs.

* Adds option in SConstruct to build FreeLAN with or without UPnP support.

* Makes miniupnpcplus::upnp_device class noncopyable.

* Be sure to have upnp flag for all SConstruct targets.

* Adds some logs.

* Uses std::unique_ptr rather than raw pointer and minor logic fixes.

* Updates appveyor.yml to add miniupnpc dependency.
  • Loading branch information
s-vincent authored and ereOn committed Aug 12, 2017
1 parent 4e0721a commit 213ad11
Show file tree
Hide file tree
Showing 33 changed files with 1,115 additions and 49 deletions.
32 changes: 32 additions & 0 deletions .party
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,35 @@ Attendee('curl').get_build('msvc-x64').commands = [
r'nmake /f Makefile.vc mode=static VC=15 WITH_DEVEL={{prefix}} DEBUG=yes GEN_PDB=yes MACHINE=x64',
r'xcopy ..\builds\libcurl-vc15-x64-debug-static-ipv6-sspi-winssl {{prefix}}\Debug\ /S /Y',
]

# miniupnpc
Attendee('miniupnpc', filter=('msvc'))
Attendee('miniupnpc').add_build('msvc-x86', environment='system', filter='msvc-x86', prefix='x86')
Attendee('miniupnpc').add_build('msvc-x64', environment='system', filter='msvc-x64', prefix='x64')
Attendee('miniupnpc').add_source('https://github.com/miniupnp/miniupnp/archive/miniupnpd_2_0.zip', filter='windows', mimetype='application/zip')
Attendee('miniupnpc').get_build('msvc-x86').commands = [
r'"C:\Program Files\CMake\bin\cmake.exe" ./miniupnpc/',
r'msbuild .\upnpc-static.vcxproj /p:Platformtoolset=v141 /p:WindowsTargetPlatformVersion=10.0.15063.0 /p:Configuration=Release /p:Platform="Win32"',
r'msbuild .\upnpc-static.vcxproj /p:Platformtoolset=v141 /p:WindowsTargetPlatformVersion=10.0.15063.0 /p:Configuration=Debug /p:Platform="Win32"',
r'md {{prefix}}\Release\lib || echo',
r'md {{prefix}}\Release\include\miniupnpc || echo',
r'md {{prefix}}\Debug\lib || echo',
r'md {{prefix}}\Debug\include\miniupnpc || echo',
r'copy Release\miniupnpc.lib {{prefix}}\Release\lib\miniupnpc.lib',
r'copy Debug\miniupnpc.lib {{prefix}}\Debug\lib\miniupnpcd.lib',
r'xcopy miniupnpc\*.h {{prefix}}\Release\include\miniupnpc\ /S /Y',
r'xcopy miniupnpc\*.h {{prefix}}\Debug\include\miniupnpc\ /S /Y',
]
Attendee('miniupnpc').get_build('msvc-x64').commands = [
r'"C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_GENERATOR_PLATFORM=x64 ./miniupnpc/',
r'msbuild .\upnpc-static.vcxproj /p:Platformtoolset=v141 /p:WindowsTargetPlatformVersion=10.0.15063.0 /p:Configuration=Release /p:Platform="x64"',
r'msbuild .\upnpc-static.vcxproj /p:Platformtoolset=v141 /p:WindowsTargetPlatformVersion=10.0.15063.0 /p:Configuration=Debug /p:Platform="x64"',
r'md {{prefix}}\Release\lib || echo',
r'md {{prefix}}\Release\include || echo',
r'md {{prefix}}\Debug\lib || echo',
r'md {{prefix}}\Debug\include || echo',
r'copy Release\miniupnpc.lib {{prefix}}\Release\lib\miniupnpc.lib',
r'copy Debug\miniupnpc.lib {{prefix}}\Debug\lib\miniupnpcd.lib',
r'xcopy miniupnpc\*.h {{prefix}}\Release\include\miniupnpc\ /S /Y',
r'xcopy miniupnpc\*.h {{prefix}}\Debug\include\miniupnpc\ /S /Y',
]
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ addons:
- libboost-all-dev
- libssl-dev
- libcurl4-openssl-dev
- libminiupnpc-dev
- gcc
- g++
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list scons &>/dev/null || brew install scons ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list boost &>/dev/null || brew install boost ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list openssl &>/dev/null || brew install openssl ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list miniupnpc &>/dev/null || brew install miniupnpc ; fi
cache:
apt: true
script: scons install apps samples
Expand Down
7 changes: 4 additions & 3 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Third-party libraries
FreeLAN depends on the following libraries:

- libcurl4
- libminiupnpc
- boost
- OpenSSL
- iconv (Windows)
Expand All @@ -17,7 +18,7 @@ to build these libraries explicitely.

To build the third-party libraries, you can use
[teapot](https://github.com/freelan-developers/teapot) (be sure to have `python
2.7` and `perl` installed). Check its
2.7`, `cmake` and `perl` installed). Check its
[documentation](http://teapot-builder.readthedocs.org/en/latest/) for details,
or just type the following command at the root of FreeLAN's repository:

Expand All @@ -33,7 +34,7 @@ following command:

> sudo apt-get install scons python libssl-dev libcurl4-openssl-dev
> libboost-system-dev libboost-thread-dev libboost-program-options-dev
> libboost-filesystem-dev libboost-iostreams-dev build-essential
> libboost-filesystem-dev libboost-iostreams-dev libminiupnpc-dev build-essential
### Mac OSX

Expand All @@ -44,7 +45,7 @@ To install the required dependencies on Mac OS, type the following commands:
> brew update
> brew install scons boost openssl
> brew install scons boost openssl miniupnpc
Building FreeLAN
----------------
Expand Down
6 changes: 6 additions & 0 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ for x in Glob('libs/*'):
if env.mongoose == 'no' and name in 'mongooseplus':
continue

if env.upnp == 'no' and name in 'miniupnpcplus':
continue

library, library_includes = SConscript(sconscript_path, exports='env dirs name')
libraries.extend(library)
includes.extend(library_includes)
Expand All @@ -68,6 +71,9 @@ if env.mode != 'retail':
if libname in 'netlinkplus':
continue

if libname in 'miniupnpcplus':
continue

for y in x.glob('*'):
sconscript_path = y.File('SConscript')

Expand Down
27 changes: 20 additions & 7 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ AddOption(
default='no',
help='Build webserver with mongoose (warning: it will violate GPLv3 license to distribute binaries built with this switch turned on!)',
)

AddOption(
'--upnp',
dest='upnp',
nargs=1,
action='store',
choices=('yes', 'no'),
default='yes',
help='Build FreeLAN with UPnP support.',
)

class FreelanEnvironment(Environment):
"""
A freelan specific environment class.
"""

def __init__(self, mode, prefix, bin_prefix=None, mongoose='no', **kwargs):
def __init__(self, mode, prefix, bin_prefix=None, **kwargs):
"""
Initialize the environment.
Expand Down Expand Up @@ -79,6 +87,7 @@ class FreelanEnvironment(Environment):
self.bin_prefix = bin_prefix if bin_prefix else prefix
self.destdir = self['ENV'].get('DESTDIR', '')
self.mongoose = mongoose
self.upnp = upnp

if self.destdir:
self.install_prefix = os.path.normpath(
Expand Down Expand Up @@ -129,8 +138,11 @@ class FreelanEnvironment(Environment):
else:
self.Append(CXXFLAGS='-O3')

if self.mongoose == 'yes':
self.Append(CXXFLAGS=['-DUSE_MONGOOSE'])
if self.mongoose == 'yes':
self.Append(CXXFLAGS=['-DUSE_MONGOOSE'])

if self.upnp == 'yes':
self.Append(CXXFLAGS=['-DUSE_UPNP'])

self.Append(CPPDEFINES=r'FREELAN_INSTALL_PREFIX="\"%s\""' % self.prefix)

Expand Down Expand Up @@ -177,6 +189,7 @@ class FreelanEnvironment(Environment):

mode = GetOption('mode')
mongoose = GetOption('mongoose')
upnp = GetOption('upnp')
prefix = os.path.normpath(os.path.abspath(ARGUMENTS.get('prefix', './install')))

if 'bin_prefix' in ARGUMENTS:
Expand All @@ -185,7 +198,7 @@ else:
bin_prefix = None

if mode in ('all', 'release'):
env = FreelanEnvironment(mode='release', prefix=prefix, bin_prefix=bin_prefix, mongoose=mongoose)
env = FreelanEnvironment(mode='release', prefix=prefix, bin_prefix=bin_prefix, mongoose=mongoose, upnp=upnp)
libraries, includes, apps, samples, configurations = SConscript('SConscript', exports='env', variant_dir=os.path.join('build', env.mode))
install = env.Install(os.path.join(env.bin_install_prefix, 'bin'), apps)
install.extend(env.Install(os.path.join(env.install_prefix, 'etc', 'freelan'), configurations))
Expand All @@ -196,15 +209,15 @@ if mode in ('all', 'release'):
Alias('all', install + apps + samples)

if mode in ('all', 'debug'):
env = FreelanEnvironment(mode='debug', prefix=prefix, mongoose=mongoose)
env = FreelanEnvironment(mode='debug', prefix=prefix, mongoose=mongoose, upnp=upnp)
libraries, includes, apps, samples, configurations = SConscript('SConscript', exports='env', variant_dir=os.path.join('build', env.mode))
Alias('apps', apps)
Alias('samples', samples)
Alias('all', apps + samples)

if sys.platform.startswith('darwin'):
retail_prefix = '/usr/local'
env = FreelanEnvironment(mode='retail', prefix=retail_prefix, mongoose=mongoose)
env = FreelanEnvironment(mode='retail', prefix=retail_prefix, mongoose=mongoose, upnp=upnp)
libraries, includes, apps, samples, configurations = SConscript('SConscript', exports='env', variant_dir=os.path.join('build', env.mode))
package = SConscript('packaging/osx/SConscript', exports='env apps configurations retail_prefix')
install_package = env.Install('.', package)
Expand Down
6 changes: 6 additions & 0 deletions apps/freelan/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ if env.mongoose == 'yes':
'mongooseplus',
])

if env.upnp == 'yes':
libraries.extend([
'miniupnpcplus',
'miniupnpc',
])

env = env.Clone()
env.Prepend(LIBS=libraries)

Expand Down
5 changes: 5 additions & 0 deletions apps/freelan/config/freelan.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ public_endpoint=0.0.0.0
#elliptic_curve_capability=sect571k1
#elliptic_curve_capability=secp384r1

# Enable UPnP to traverse NAT
#
# Default: yes
#upnp_enabled=yes

[tap_adapter]

# The tap adapter type.
Expand Down
Loading

0 comments on commit 213ad11

Please sign in to comment.