1

I want to build an application for Raspberry Pi (C++, Boost, OpenSSL) that handles file download/upload requests (and other custom actions). The RPi has an external HDD connected to it (through USB). Let's call it simply Storage (RPi + HDD).

I have a public server that I can configure for any need. The problem is that the Storage is behind a router that I don't have access to configure (port forwarding is excluded), so, the public server cannot connect to Stroage directly.

Programmatically, what is the optimal way to communicate between a client (web browser / mobile application) and Storage through the public server? A simple use case is this: I want to download a file from Storage to my phone over the internet.

I can think of two possible solutions:

  1. Maintain a tunnel open between public server and Storage. Is this scalable for multiple Storages (assuming that the public server will serve many of them in the future)?
  2. The Storage pings every let's say 3 seconds the public server (more like announces server that it is online) and if the public server has a request from a client, then a full connection will be established (client <-> public server <-> Storage) and the file download/upload request will be handled normally.

How can I implement this (third party tools like Weaved is excluded) and what other possibilities are there? Also, are the two alternative I described above even viable?

The overall sistem architecture looks like the one below.

I know that this is a more general question, but I don't know how to approach my particular case.

Remote Raspberry Pi requests

7
  • The Pi seems irrelevant to the question. You should be able to find a better site for the question, perhaps another stack exchange site?
    – joan
    Aug 27, 2015 at 20:32
  • Thank you for your suggestion. I couldn't think of a more suitable site for this question (stackoverflow is based on programming specific details and superuser is more like a site for general technology related questions). Can you recommend where should I move this question? Aug 27, 2015 at 20:37
  • I'm afraid I can't. I only visit this stack exchange site. I'm sure someone more knowledgeable will have an idea.
    – joan
    Aug 27, 2015 at 20:56
  • A hint... Since you can't port forward, the connection would need to be opened the other direction and persistent (doesn't close and kept alive. If you actually get it working tho, you'll find performance to be too awful to use as cloud storage.
    – Tyson
    Aug 27, 2015 at 22:38
  • 1
    There is networking stackexchange site, I'm sure they can help.
    – 10robinho
    Aug 28, 2015 at 9:02

1 Answer 1

2

I'll assume your app works on port X.

Install ssh server on PS (public server).

Connect via ssh to PS, and create a reverse port forward, from PS:127.0.0.1:Y (port Y on PS) to S:x

Create a daemon on PS, to listen on port Z. When someone connects to port Z on PS and authenticates (or whatever you need to do) stream data between that new connection and PS:127.0.0.1:Y.

This removes the need of port forwards.

If you want to take a step further, you can use a hole-punching library to try to do a direct connection (but this is much harder than the above solution).

You need to ensure the ssh server on ps allows no commands except authentication and reverse port forward, to disallow S clients to do things on the server (if this is desired).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.