Code center > Darwinbots3

P2P Internet Mode

<< < (3/12) > >>

goffrie:

--- Quote from: EricL ---there are serious security issues to overcome in such an architecture depending upon the protocol and the means by which the P2P communication is acheived.  Anytime you start running server code (meaning code that listens for new requests on a port and performs work based on those requests) on clients, you open up a serious security can of works not to mention isuses with NATs and firewalls, etc.
--- End quote ---
Security issues perhaps are a problem, but they are only moderately severe as long as code is kept well-managed. Issues with NATs can be overcome by relaying through the central server.


--- Quote ---People should not confuse the client connectivity topology we choose to use with transport latency issues or with the connectivty problems inherent in the current FPT-based design.  The current FTP based thing is problematic to be sure, but the connectivity problems are not inherent problems with the design.  Those can be fixed by moving to a more reilable server and moving the server communication code out of proc, both of which I am working on (using in part, some code from Nums).
--- End quote ---
I'm not talking about latency issues or connectivity problems, I'm just talking about a peer-to-peer system. Moving to a more reliable server would help with thse issues, though, which is definitely appreciated.
"moving the server communication code out of proc" - I'm not too sure what you meant by this.
 

--- Quote ---But we will reach scalability limits on the current architecture.  Understand, there is no real server today.  No server that is, other than the FTP server itself.
--- End quote ---
Which is a real server.


--- Quote ---There is no code authored by me running on any machine except the client simulators each of us run. They cooperate through the FTP server by moving files, but in an incredibly ineffecient manner becuase they are forced to shoe horn their semantics into file movements and the semantics of the FTP protocol.  Some poeple call this a shared-file or file-sharing version of cleint-server.  Early corporate email systems (circa 1990) such as CC:Mail and Mcirosoft Mail used this archtiecture.   It is not true client-server (like POP/SMTP).  Were we to move to a true client-server model where we had special code runnnig on a server, implimenting our specific semantics, we could easily scale to several thousand sims connected through a single server.  Buidling this on top of HTTP or PHP or sockets or whatever is mostly a discussion of ease of implimentation.  The result is the same, a true cleint-server architecture. Scaling beyond that would require mutliple servers with connection logic or partitioning or a P2P architecuture.
--- End quote ---
... Why the lecture? I don't see what point you're trying to make.


--- Quote ---As a followup to my last post... There are there any problems having the download script save data to disk? If there is, is it possible to embed binary data in the HTTP the PHP script returns? If that wouldn't work either, an text based organism file would probably be possible. I know for sure that would work...
--- End quote ---
Yes, you can put binary data into an HTTP stream - how do you think binary downloads work?


--- Quote ---Which leaves uploading the file, which is where I don't know how to proceed.
--- End quote ---
Neither do I, since I'm not familiar with VB.

Numsgil:

--- Quote from: goffrie ---
--- Quote ---As a followup to my last post... There are there any problems having the download script save data to disk? If there is, is it possible to embed binary data in the HTTP the PHP script returns? If that wouldn't work either, an text based organism file would probably be possible. I know for sure that would work...
--- End quote ---
Yes, you can put binary data into an HTTP stream - how do you think binary downloads work?  

--- End quote ---

Magic lawn leprachauns.  You ask for the file you want to download, and they use their magic to force their way in to a parallel dimension where I already have the file.  They then murder than alternate me, and steal his computer's hard drive.  Using their magics they teleport the bits from the stolen hard drive to my own.  And voila, I have the file I wanted to download


--- Quote ---
--- Quote ---Which leaves uploading the file, which is where I don't know how to proceed.
--- End quote ---
Neither do I, since I'm not familiar with VB.

--- End quote ---

Well, let's ignore the whole VB thing for a moment.  If this were for a web site, and we wanted someone to click on a link that would automatically upload a certain file, how would that work?

goffrie:

--- Quote from: Numsgil ---Magic lawn leprachauns.  You ask for the file you want to download, and they use their magic to force their way in to a parallel dimension where I already have the file.  They then murder than alternate me, and steal his computer's hard drive.  Using their magics they teleport the bits from the stolen hard drive to my own.  And voila, I have the file I wanted to download
--- End quote ---



--- Quote from: Numsgil ---Well, let's ignore the whole VB thing for a moment.  If this were for a web site, and we wanted someone to click on a link that would automatically upload a certain file, how would that work?
--- End quote ---
It wouldn't - you can't force a user to upload a file without using client-side things like Javascript (and even then I don't think that would work.) Basically, it poses too much of a security risk to work.
The VB part comes in because you need to voluntarily put the data stream into the request.

Hmm, I found this information for VB6:

--- Quote ---The transaction with Google happen via HTTP POST requests. There is a control available in VS6 that allows you to perform these simply; the Microsoft Internet Transfer Control. It is basically a wrapper around the WinInet Windows API, making it nice and easy to use. To add this to your project, start a new standard .exe project in VB6. Go to the Project menu, then Components and pick the "Microsoft Internet Transfer Control". Click OK, and a component will be added to the components toolbox ready for use. Drop one of these onto your form.

(...)

In Visual Basic, you can do it as below this. Imagine Inet1 is the  name of the Internet Transfer Control you added above, and your email  address, password and application ID are stored in the string variables  "myEmail", "myPassword" and "mySource". Note the use of the  form-urlencoded Content-Type header.  

--- Code: ---   strURL = "https://www.google.com/accounts/ClientLogin"
   strFormData  = "Email=" & myEmail & "&Passwd=" & myPassword &  "&source=" & mySource & "&service=cl"
   strHeaders = "Content-Type:application/x-www-form-urlencoded"
   Inet1.Execute strURL, "POST", strFormData, strHeaders
--- End code ---
Your application needs to wait for Google to respond. Do this by  looking out for the icResponseCompleted event in the Inet1_StateChanged  event handler. When it does, store Google's reply in a variable, e.g.:


--- Code: ---vtData = Inet1.GetChunk(1024, icString)
   </p>  <div class="codeblock"><code>      Do While LenB(vtData) > 0
           outputString = outputString + vtData      
            ' Get next chunk.
            vtData = Inet1.GetChunk(1024, icString)
         Loop      
      Response = outputString</code></div>
--- End code ---

--- End quote ---


I suppose you could use this code (replacing the strFormData with "data=some-encoded-form-of-dbo" and the strURL to an appropriate address) to send a file to the server. On the server side, in PHP, $_POST['data'] would contain the encoded data.

Numsgil:
Hmm...  so bear with me if this is a stupid question.  I know some data can be embedded in the url (such as the forum url: index.php?showtopic=2808).  And other data can be sent behind the scenes, not in the URL.  For instance, when I write a really long, almost novel-like, post, all that text seems to get embedded in the stream somehow.  I think the two different types are called POST and GET, IIRC.  So... on the VB (or C#) side of things I can convert a file I want to upload in to a binary data stream.  Let's say, for the sake of argument, that the data stream is about 3MB large.  How would the web server running the PHP script expect to get that data?  What would the PHP script look like that took that data and saved it to a file somewhere?

goffrie:

--- Quote from: Numsgil ---Hmm...  so bear with me if this is a stupid question.  I know some data can be embedded in the url (such as the forum url: index.php?showtopic=2808).  And other data can be sent behind the scenes, not in the URL.  For instance, when I write a really long, almost novel-like, post, all that text seems to get embedded in the stream somehow.  I think the two different types are called POST and GET, IIRC.  So... on the VB (or C#) side of things I can convert a file I want to upload in to a binary data stream.  Let's say, for the sake of argument, that the data stream is about 3MB large.  How would the web server running the PHP script expect to get that data?  What would the PHP script look like that took that data and saved it to a file somewhere?
--- End quote ---

Data embedded in the URL is GET data, and the data embedded "behind the scenes" as you put it is POST data.
Your 3MB data stream would be sent via POST "behind the scenes", and then the PHP script would receive it like this:

--- Code: ---   <?php
   if (!isset($_POST['data'])) die("No data sent via POST!");
   $data = trim($_POST['data']); // now $data contains the encoded data - "trim" removes any excess spaces, newlines etc. around it
   $data = base64_decode($data); // assuming base64 encoding, $data now has the binary data. PHP is binary-safe in general but some functions aren't
   $file = @fopen('files/'.time().'.dbo', 'w'); // now open files/(current UNIX timestamp) for writing ('w'). time() returns an integer but it is implicitly converted to a string. the @ suppresses errors
   if (!$file) die("Error opening file ".time().".dbo for writing!"); // error checking
   fwrite($file,$data) or die("Error writing file!"); // write the binary data to the file. the 'or die("")' syntax is quite common for easy error checking, I could have used it for $file but meh
   fclose($file); // close the file. not mandatory
   ?>
--- End code ---
This PHP script would take base64 encoded data from the POST stream as the "data" variable (like "data=encodeddata"), decode it, and write it to "files/(time).dbo". Of course, this script would have problems with multiple files being uploaded in the same second - a different file scheme would fix that.
A shortened version (it generates a few warnings/notices on error):

--- Code: --- <?php
 fwrite(fopen('files/'.time().'.dbo','w'),base64_decode(trim($_POST['data']))) or die("Failed!");
 ?>
--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version