maandree / cnt

Coop Network Tetris, a university project.
maandree.github.com/cnt
4 stars 1 forks source link

Change ConnectionNetworking #23

Closed aiqueneldar closed 12 years ago

aiqueneldar commented 12 years ago

ConnectionNetworking should handle everything that is needed for building and maintaining the cloud and assigning ID:s.

ConnectionNetworking as one input stream which ObjectNetworking writes to. ConnectionNetworking registrers one input stream to ObjectNetworking for each socket, ObjectNetworking creates a thread that reads from that input stream and adds fetched objects to a deque. ConnectionNetworking parses streams and strips them down to only the objects which are read by ObjectNetworking, ConnectionNetworking most also, directly before the object add one byte for the priority (0 for end of deque, 1 for beginning of deque) and 4 bytes for the players ID that sent the object.

A message is not necessarily send from the client from whom you got the message. Consider that you have 3 clients: A, B and C. A is only connected to B, B is connected to both A and C, and C is only connected to B. Messages send from C to B is forwarded from B to A, and messages from A is sent to B and forwarded from B to C. Therefore object octets, which by be invalid, must therefor be sent with the ID of the original sender, otherwise we do known know how to kick, object octets are not valided by ConnectionNetworking before forward, but by GameNetworking (for integrity) and ObjectNetworking (for actuality) asynchronously.

I messages consists of three parts: head, body and foot

The first byte in a head is a '+' if it is urgent. After the '+' or, if none, at the beginning the is either a '?'. '!' or 'O'. '?' marks a ConnectionNetworking internal question. '!' marks a ConnectionNetworking internal information which may be, for example, an ID assignment or an answer on a '?' question. 'O' marks an Object send higher up on the networking stack. 'O' is directly followed by exactly 4 bytes which identifies the original sender of the object.

The body consists of bytes, if a byte is NUL (= 0 = \0) it must be prepended by an ESC (= 27 = [\e] = \033). If ESC is used as a byte of the body, it must also be prepended by an ESC. ESC is used for telling that the next byte is a part of the message and should not have a special meaning, think of it like using \ before " to create a " instead of ending a string.

The foot is one byte long and is just a NUL.

aiqueneldar commented 12 years ago

Can you upload the diagram showing how ConnectionNetworking and ObjectNetworking was to communicate again? Also with a description. I vaguely remember what we said in the meeting, but need a lot of reminding.

aiqueneldar commented 12 years ago

I say commands are sent in ASCII so that we get no problem with character encoding? Or should we just choose arbitarely byte numbers and assign them the '!', '?', 'O', '+' meanings and just pick a number even if that happens not to be the sign when converted from byte to string?

aiqueneldar commented 12 years ago

ASCII numbers for signs are '!' = 33 = \041 '+' = 43 = \053 '?' = 63 = \077 'O' = 79 = \117

maandree commented 12 years ago

ASCII strings are nice and human readable. Theoretically UTF-8 is no problem at all, except, ASCII uses exactly one byte per character an is thus easier to understand the code with.

maandree commented 12 years ago

I have upload the diagram to the branch develop, as will as in the branch binary.

aiqueneldar commented 12 years ago

Found some other forum theads and the like wich didn't incurage the use of UTF-8 and the like because it was extra hard to correctly convert between byte values and readable again. That's why i suggested that we use ASCII

maandree commented 12 years ago

Yes, UTF-8 is extra hard, I see no use of it. The information should be in English, if we should happen to run into a word that cannot be written in ASCII, then we can just make it ASCII, and those are very rear.

String that are not interpreted, such as names, however should be in UTF-8, if they happen to be in using message instead of in objects.

aiqueneldar commented 12 years ago

As I understood it, it will be impractical to use UTF-8 ever in low level, so I suggest we ban it and only ever use it inside high-level. See no need for names to be sent in low-level protocoll anyway

maandree commented 12 years ago

Yes.

However we will not use UTF-8 in high-level, we will use String whose encoding we will [most like] never need to care about. But they are encoded in the UTF-16, and transfered in modified UTF-8. [And yes it is weird to transfer in an encoding that has a wider range of character.]

aiqueneldar commented 12 years ago

Can't we use the ordinary ObjectInputStream and ObjectOutputStreams instead of either the broken piped streams or custom made ones?

maandree commented 12 years ago

Object_Stream(Buffered_Stream(⋅)) is used for reading objects. Non-broken Piped*Stream:s are available in cnt.mock, but should be moved to cnt.util.

Piped*Stream should be used when one thread writes and the other thread reads. The streams registered to ObjectNetworking for reading objects does not need this; and I cannot think of any case where it is technically required, but I would use it for the stream used to send objects from ObjectNetworking to ConnectionNetworking.