SlideShare a Scribd company logo
1 of 50
Download to read offline
A walk through building & stacking
          protocols using Kamaelia




                       Michael Sparks
                        October 2008
The aim of this document is to guide you
through building a system where:

● A user connects to a server and
● Over a secure connection,

● Receives a sequence of JSON encode-able


  objects
The aim of this document is to guide you
through building a system where:

● A user connects to a server and
● Over a secure connection,
                    This doc also uses speech
● Receives a sequence of JSON make “aside”
                 bubbles like this to encode-able
                  comments regarding particlar
  objects        panels. You can skip these safely.
ServerCore




First of all, we start off with the ServerCore
component. The hole is for fitting a protocol
handler factory. eg a class, or function.
ServerCore



                     As an aside, this hole is pretty
                    crucial. Without filling this hole,
                   this component is pretty useless.
                         So we call this sort of
                        component a CHASSIS

First of all, we start off with the ServerCore
component. The hole is for fitting a protocol
handler factory. eg a class, or function.
ServerCore




           «factory»
           protocol




So, we provide a protocol factory.
ServerCore(protocol=protocol, port=2345)
ServerCore




           «factory»
           protocol      In retrospect, “protocol” as the
                          name of an example protocol
                          handler is a bad idea, so let's
                               change this slightly.
So, we provide a protocol factory.
ServerCore(protocol=protocol, port=2345)
ServerCore




           «factory»
         stackedjson




So, we provide a protocol factory.
ServerCore(protocol=stackedjson,
           port=2345)
ServerCore




           «factory»
         stackedjson




We then activate it, which causes it to start a
subcomponent.
   ServerCore( .... )
ServerCore


         TCPServer




          «factory»
        stackedjson




We then activate it. It starts TCPServer
subcomponent, which listens for connections.
  ServerCore( .... ).activate()
ServerCore

                          Connected
         TCPServer       SocketAdapter




          «factory»
        stackedjson




A client then connects to the TCPServer which
creates a ConnectedSocketAdapter to handle
the mechanics of the connection.
ServerCore

                           Connected
         TCPServer        SocketAdapter




          «factory»
                          stackedjson
        stackedjson




TCPServer tells ServerCore it has done this.
ServerCore in response calls the protocol factory
to create a handler component...
ServerCore

                           Connected
         TCPServer        SocketAdapter




          «factory»
                          stackedjson
        stackedjson




...which is wired up. The protocol handler just
receives bytes and sends bytes, which are sent to
the client via the ConnectedSocketAdapter
ServerCore

                            Connected
          TCPServer        SocketAdapter




           «factory»
                           stackedjson
         stackedjson




There, the key thing in creating a server, is to
create an appropriate protocol handler
component.
ServerCore

                            Connected
          TCPServer        SocketAdapter




           «factory»
                           stackedjson
         stackedjson




There, the key thing in creating a server, is to
create an appropriate protocol handler
component.
stackedjson




So, let's look inside this component
stackedjson


def protocol(*args,**argd):
    return Pipeline(
             PeriodicWakeup(message=quot;NEXTquot;, interval=1),
             Chooser(messages),
             MarshallJSON(),
             Encrypter(),
             DataChunker(),
        )


So, let's look inside this component
stackedjson


def protocol(*args,**argd):
    return Pipeline(
             PeriodicWakeup(message=quot;NEXTquot;, interval=1),
             Chooser(messages),
             MarshallJSON(),
             Encrypter(),
             DataChunker(),
        )


So, let's look inside this component.
Clearly this is what actually handles the
connection.
PeriodicWakeup

    Chooser       Pipeline(
                      PeriodicWakeup(message=quot;NEXTquot;,
  MarshallJSON                       interval=1),
                      Chooser(messages),
    Encrypter         MarshallJSON(),
                      Encrypter(),
  DataChunker         DataChunker(),
                   )




Let's expand that...
PeriodicWakeup

    Chooser

  MarshallJSON
                  Direction of
    Encrypter
                  data flow

  DataChunker




We see this is a uni-directional protocol – as
soon as this pipeline starts up. Encrypted JSON
data chunks get sent, ignoring client data.
PeriodicWakeup

    Chooser                       ConsoleEchoer

  MarshallJSON                   DeMarshallJSON
                  Direction of
    Encrypter       data flow       Decrypter

  DataChunker                    DataDeChunker

                                    TCPClient


So, given the ServerCore infrastructure means
we can more or less ignore the network, what
does the client side pipeline look like?
PeriodicWakeup

    Chooser                        ConsoleEchoer

  MarshallJSON                    DeMarshallJSON

    Encrypter                        Decrypter

  DataChunker                     DataDeChunker

                                     TCPClient


Each component in the server, that is part of the
user's protocol, has a matching component in
the client.
PeriodicWakeup

    Chooser                          ConsoleEchoer

  MarshallJSON                      DeMarshallJSON

    Encrypter                          Decrypter

  DataChunker                       DataDeChunker

                                       TCPClient


Fundamentally, this protocol allows one side of
it to securely throw dictionary objects to clients
which can then do something with them
PeriodicWakeup

    Chooser                        ConsoleEchoer

  MarshallJSON                     DeMarshallJSON

    Encrypter                         Decrypter

  DataChunker                      DataDeChunker

                                     TCPClient


To understand what a client sees, we just look at
these three components. The 2 highlighted
server side components are the core behaviour.
PeriodicWakeup



      Chooser




    ConsoleEchoer




Let's rearrange these, showing the logical
pipeline that drives what the user sees.
PeriodicWakeup(
   PeriodicWakeup         message=quot;NEXTquot;,
                          interval=1)

      Chooser




   ConsoleEchoer




First of all the PeriodicWakeupComponent
sends out the message “NEXT” once per second.
Messages = [
   PeriodicWakeup            {quot;helloquot;:   quot;worldquot; },
                             {quot;helloquot;:   [1,2,3] },
                             {quot;worldquot;:   [1,2,3] },
                             {quot;worldquot;:   {quot;gamequot;:quot;overquot;} },
      Chooser
                    ]*10

                    Chooser(messages)
   ConsoleEchoer




These “NEXT” messages control the Chooser.
The chooser steps through a list of messages,
and when told “NEXT”, sends the next message.
Messages = [
   PeriodicWakeup              {quot;helloquot;: quot;worldquot; },
                               {quot;helloquot;: [1,2,3] },
                               {quot;worldquot;: [1,2,3] },
                        It's worth noting that the Chooser
      Chooser          can back backwards{quot;gamequot;:quot;overquot;} },
                               {quot;worldquot;: as well, just to
                    ]*10
                        the start and end etc. For more
                    Chooser(messages)at the docs :)
                           details look
   ConsoleEchoer




These “NEXT” messages control the Chooser.
The chooser steps through a list of messages,
and when told “NEXT”, sends the next message.
PeriodicWakeup



      Chooser


                    ConsoleEchoer(use_repr=True)
   ConsoleEchoer




These messages arrive intact at the client - in
this case a ConsoleEchoer. However it could be
something more interesting – eg a game system.
PeriodicWakeup

    Chooser                       ConsoleEchoer

  MarshallJSON                    DeMarshallJSON

    Encrypter                        Decrypter

  DataChunker                     DataDeChunker

                                    TCPClient


Going back to the overview slide, this diagram
shows the various protocols which are stacked
on top of each other.
PeriodicWakeup

    Chooser                       ConsoleEchoer

  MarshallJSON                   DeMarshallJSON

    Encrypter                       Decrypter

  DataChunker                    DataDeChunker

                                    TCPClient


We have our core application protocol, stacked
on top of a secure serialising communications
channel. This truly is at the application level.
PeriodicWakeup

    Chooser                       ConsoleEchoer

  MarshallJSON                   DeMarshallJSON

    Encrypter                       Decrypter

  DataChunker                     DataDeChunker

                                    TCPClient


We have our serialisation protocol. Clearly this
is a message oriented protocol – it requires the
lower layer to preserve boundaries.
PeriodicWakeup

    Chooser                         ConsoleEchoer

  MarshallJSON                     DeMarshallJSON

    Encrypter                         Decrypter

  DataChunker                       DataDeChunker

                                      TCPClient


We have a secure transmission protocol.
This is admittedly simplistic – it assumes
predistributed keys. However it gives a flavour
PeriodicWakeup

    Chooser                    ConsoleEchoer

  MarshallJSON                 DeMarshallJSON

    Encrypter                     Decrypter

  DataChunker                  DataDeChunker

                                 TCPClient


We then have our chunking protocol, which
preserves message boundaries – necessary
because TCP does not guarantee to do so.
PeriodicWakeup

    Chooser                        ConsoleEchoer

  MarshallJSON                     DeMarshallJSON

    Encrypter                         Decrypter

  DataChunker                      DataDeChunker

                                     TCPClient


So let's go back and see where these things fit
back into the system.
ServerCore

                          Connected
       TCPServer         SocketAdapter




        «factory»
                         stackedjson
      stackedjson




So this is what we had ...
ServerCore

                            Connected
        TCPServer          SocketAdapter




         «factory»
                           stackedjson
       stackedjson




The client really looks like this...
Also, this is a one way protocol
ServerCore

                          Connected
       TCPServer         SocketAdapter




        «factory»
      stackedjson




The client really looks like this & this is a one
way protocol. The protocol itself looks like this.
And that's how those parts fit together.
ServerCore

                          Connected
       TCPServer         SocketAdapter




        «factory»
      stackedjson




So, finally, for completeness, we'll include the
code.
So, finally, for completeness, we'll include the
code.

Though, for code, this is a better location:
           http://tinyurl.com/4k3df2
Bunch of imports...
import cjson
import Axon

from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Chooser import Chooser
from Kamaelia.Util.Console import ConsoleEchoer

from Kamaelia.Internet.TCPClient import TCPClient
from Kamaelia.Chassis.ConnectedServer import ServerCore

from Kamaelia.Protocol.Framing import DataChunker, DataDeChunker
from Kamaelia.Apps.Grey.PeriodicWakeup import PeriodicWakeup

from Crypto.Cipher import DES
Define the messages being slung to clients
messages = [ {quot;helloquot;:   quot;worldquot; },
             {quot;helloquot;:   [1,2,3] },
             {quot;worldquot;:   [1,2,3] },
             {quot;worldquot;:   {quot;gamequot;:quot;overquot;} },
           ]*10
Then the JSON De/Marshalling components
class MarshallJSON(Axon.Component.component):
    def main(self):
        while not self.dataReady(quot;controlquot;):
            for j in self.Inbox(quot;inboxquot;):
                j_encoded = cjson.encode(j)
                self.send(j_encoded, quot;outboxquot;)
            if not self.anyReady():
                self.pause()
            yield 1

class DeMarshallJSON(Axon.Component.component):
    def main(self):
        while not self.dataReady(quot;controlquot;):
            for j in self.Inbox(quot;inboxquot;):
                j_decoded = cjson.decode(j)
                self.send(j_decoded, quot;outboxquot;)
            if not self.anyReady():
                self.pause()
            yield 1
Define our encoding layer using normal code...1
class Encoder(object):
    quot;quot;quot;Null encoder/base encoder - returns the same string
       for encode/decodequot;quot;quot;
    def __init__(self, key, **argd):
        super(Encoder, self).__init__(**argd)
        self.__dict__.update(argd)
        self.key = key
    def encode(self, some_string):
        return some_string
    def decode(self, some_string):
        return some_string
Define our encoding layer using normal code...2
class DES_CRYPT(Encoder):
    def __init__(self, key, **argd):
        super(DES_CRYPT, self).__init__(key, **argd)
        self.key = self.pad_eight(key)[:8]
        self.obj = obj=DES.new(self.key, DES.MODE_ECB)

   def encode(self, some_string):
       padded = self.pad_eight(some_string)
       encrypted = self.obj.encrypt(padded)
       return encrypted

   def decode(self, some_string):
       padded = self.obj.decrypt(some_string)
       decoded = self.unpad(padded)
       return decoded

# ... continued
Define our encoding layer using normal code...3
# class DES_CRYPT(Encoder): # ... continued from before

   def pad_eight(self, some_string):
       X = len(some_string)
       if X % 8 != 0:
           pad_needed = 8-X % 8
       else:
           pad_needed = 8
       pad_needed = 8-(X % 8)
       PAD = pad_needed * chr(pad_needed)
       return some_string+PAD

   def unpad(self, some_string):
       x = ord(some_string[-1])
       return some_string[:-x]
Create Encryption components using this
class Encrypter(Axon.Component.component):
    key = quot;ABCDquot;
    def main(self):
        crypter = DES_CRYPT(self.key)
        while not self.dataReady(quot;controlquot;):
            for j in self.Inbox(quot;inboxquot;):
                 j_encoded = crypter.encode(j)
                 self.send(j_encoded, quot;outboxquot;)
            if not self.anyReady():
                 self.pause()
            yield 1
                                           Note, this is not a serious
                                           protocol, it is an illustration.
                                           This form of pre-shared key
                                           would be a bad idea, but
                                           the pattern of usage will
                                           be useful.
Create Decryption components using this
class Decrypter(Axon.Component.component):
    key = quot;ABCDquot;
    def main(self):
        crypter = DES_CRYPT(self.key)
        while not self.dataReady(quot;controlquot;):
            for j in self.Inbox(quot;inboxquot;):
                 j_decoded = crypter.decode(j)
                 self.send(j_decoded, quot;outboxquot;)
            if not self.anyReady():
                 self.pause()
            yield 1
                                           Note, this is not a serious
                                           protocol, it is an illustration.
                                           This form of pre-shared key
                                           would be a bad idea, but
                                           the pattern of usage will
                                           be useful.
Create the protocol handler factory & Client
def stackedjson(*args,**argd):
    return Pipeline(
             PeriodicWakeup(message=quot;NEXTquot;, interval=1),
             Chooser(messages),
             MarshallJSON(),
             Encrypter(),       # Encrypt on the way out
             DataChunker(),
        )

def json_client_prefab(ip, port):
    return Pipeline(
             TCPClient(ip, port=port),
             DataDeChunker(),
             Decrypter(),       # Decrypt on the way in
             DeMarshallJSON(),
             ConsoleEchoer(use_repr=True)
        )
And finally start the server and point a
client at the server.
ServerCore(protocol=protocol, port=2345).activate()
json_client_prefab(quot;127.0.0.1quot;, 2345).run()



       ServerCore

                                      Connected
           TCPServer                 SocketAdapter




            «factory»
          stackedjson

More Related Content

What's hot

Chat Room System using Java Swing
Chat Room System using Java SwingChat Room System using Java Swing
Chat Room System using Java SwingTejas Garodia
 
Complex Event Processing with Esper and WSO2 ESB
Complex Event Processing with Esper and WSO2 ESBComplex Event Processing with Esper and WSO2 ESB
Complex Event Processing with Esper and WSO2 ESBPrabath Siriwardena
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
解读server.xml文件
解读server.xml文件解读server.xml文件
解读server.xml文件wensheng wei
 
Nodejs 프로그래밍 ch.3
Nodejs 프로그래밍 ch.3Nodejs 프로그래밍 ch.3
Nodejs 프로그래밍 ch.3HyeonSeok Choi
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In JavaAnkur Agrawal
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programmingAnung Ariwibowo
 
Dynamo: Not Just For Datastores
Dynamo: Not Just For DatastoresDynamo: Not Just For Datastores
Dynamo: Not Just For DatastoresSusan Potter
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using javaUC San Diego
 
From A to Z | WireShark Tutorial
From A to Z | WireShark TutorialFrom A to Z | WireShark Tutorial
From A to Z | WireShark TutorialTurkHackTeam EDU
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныTimur Safin
 
Java- Datagram Socket class & Datagram Packet class
Java- Datagram Socket class  & Datagram Packet classJava- Datagram Socket class  & Datagram Packet class
Java- Datagram Socket class & Datagram Packet classRuchi Maurya
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitivesBartosz Sypytkowski
 

What's hot (20)

Chat Room System using Java Swing
Chat Room System using Java SwingChat Room System using Java Swing
Chat Room System using Java Swing
 
OSGi Puzzlers
OSGi PuzzlersOSGi Puzzlers
OSGi Puzzlers
 
Complex Event Processing with Esper and WSO2 ESB
Complex Event Processing with Esper and WSO2 ESBComplex Event Processing with Esper and WSO2 ESB
Complex Event Processing with Esper and WSO2 ESB
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
解读server.xml文件
解读server.xml文件解读server.xml文件
解读server.xml文件
 
Java sockets
Java socketsJava sockets
Java sockets
 
Nodejs 프로그래밍 ch.3
Nodejs 프로그래밍 ch.3Nodejs 프로그래밍 ch.3
Nodejs 프로그래밍 ch.3
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In Java
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
Dynamo: Not Just For Datastores
Dynamo: Not Just For DatastoresDynamo: Not Just For Datastores
Dynamo: Not Just For Datastores
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Lecture10
Lecture10Lecture10
Lecture10
 
Java NIO.2
Java NIO.2Java NIO.2
Java NIO.2
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using java
 
From A to Z | WireShark Tutorial
From A to Z | WireShark TutorialFrom A to Z | WireShark Tutorial
From A to Z | WireShark Tutorial
 
Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
 
Java- Datagram Socket class & Datagram Packet class
Java- Datagram Socket class  & Datagram Packet classJava- Datagram Socket class  & Datagram Packet class
Java- Datagram Socket class & Datagram Packet class
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 

Viewers also liked

Embracing concurrency for fun utility and simpler code
Embracing concurrency for fun utility and simpler codeEmbracing concurrency for fun utility and simpler code
Embracing concurrency for fun utility and simpler codekamaelian
 
Kamaelia Europython Tutorial
Kamaelia Europython TutorialKamaelia Europython Tutorial
Kamaelia Europython Tutorialkamaelian
 
Kamaelia lightning2010opensource
Kamaelia lightning2010opensourceKamaelia lightning2010opensource
Kamaelia lightning2010opensourcekamaelian
 
Practical concurrent systems made simple using Kamaelia
Practical concurrent systems made simple using KamaeliaPractical concurrent systems made simple using Kamaelia
Practical concurrent systems made simple using Kamaeliakamaelian
 
Bleach
BleachBleach
BleachKitara
 
Photoshop Club
Photoshop ClubPhotoshop Club
Photoshop ClubKitara
 
Kamaelia Grey
Kamaelia GreyKamaelia Grey
Kamaelia Greykamaelian
 
Managing Creativity
Managing CreativityManaging Creativity
Managing Creativitykamaelian
 
Timeshift Everything, Miss Nothing - Mashup your PVR with Kamaelia
Timeshift Everything, Miss Nothing - Mashup your PVR with KamaeliaTimeshift Everything, Miss Nothing - Mashup your PVR with Kamaelia
Timeshift Everything, Miss Nothing - Mashup your PVR with Kamaeliakamaelian
 
The Selfish Programmer
The Selfish ProgrammerThe Selfish Programmer
The Selfish Programmerkamaelian
 
RabbitMQ with python and ruby RuPy 2009
RabbitMQ with python and ruby RuPy 2009RabbitMQ with python and ruby RuPy 2009
RabbitMQ with python and ruby RuPy 2009Paolo Negri
 
Descriptors In Python
Descriptors In PythonDescriptors In Python
Descriptors In PythonAmit Upadhyay
 
Messaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPMessaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPEberhard Wolff
 
Data Analysis and Statistics in Python using pandas and statsmodels
Data Analysis and Statistics in Python using pandas and statsmodelsData Analysis and Statistics in Python using pandas and statsmodels
Data Analysis and Statistics in Python using pandas and statsmodelsWes McKinney
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for BeginnersJason Davies
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To DjangoJay Graves
 
Python for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandasPython for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandasWes McKinney
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in PythonSujith Kumar
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundationKevlin Henney
 

Viewers also liked (20)

Embracing concurrency for fun utility and simpler code
Embracing concurrency for fun utility and simpler codeEmbracing concurrency for fun utility and simpler code
Embracing concurrency for fun utility and simpler code
 
Kamaelia Europython Tutorial
Kamaelia Europython TutorialKamaelia Europython Tutorial
Kamaelia Europython Tutorial
 
Kamaelia lightning2010opensource
Kamaelia lightning2010opensourceKamaelia lightning2010opensource
Kamaelia lightning2010opensource
 
Practical concurrent systems made simple using Kamaelia
Practical concurrent systems made simple using KamaeliaPractical concurrent systems made simple using Kamaelia
Practical concurrent systems made simple using Kamaelia
 
Bleach
BleachBleach
Bleach
 
Photoshop Club
Photoshop ClubPhotoshop Club
Photoshop Club
 
Kamaelia Grey
Kamaelia GreyKamaelia Grey
Kamaelia Grey
 
Managing Creativity
Managing CreativityManaging Creativity
Managing Creativity
 
Timeshift Everything, Miss Nothing - Mashup your PVR with Kamaelia
Timeshift Everything, Miss Nothing - Mashup your PVR with KamaeliaTimeshift Everything, Miss Nothing - Mashup your PVR with Kamaelia
Timeshift Everything, Miss Nothing - Mashup your PVR with Kamaelia
 
The Selfish Programmer
The Selfish ProgrammerThe Selfish Programmer
The Selfish Programmer
 
RabbitMQ with python and ruby RuPy 2009
RabbitMQ with python and ruby RuPy 2009RabbitMQ with python and ruby RuPy 2009
RabbitMQ with python and ruby RuPy 2009
 
Descriptors In Python
Descriptors In PythonDescriptors In Python
Descriptors In Python
 
Messaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPMessaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQP
 
Django introduction
Django introductionDjango introduction
Django introduction
 
Data Analysis and Statistics in Python using pandas and statsmodels
Data Analysis and Statistics in Python using pandas and statsmodelsData Analysis and Statistics in Python using pandas and statsmodels
Data Analysis and Statistics in Python using pandas and statsmodels
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To Django
 
Python for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandasPython for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandas
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 

Similar to Kamaelia Protocol Walkthrough

Cassandra 2.1 boot camp, Overview
Cassandra 2.1 boot camp, OverviewCassandra 2.1 boot camp, Overview
Cassandra 2.1 boot camp, OverviewJoshua McKenzie
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuningprathap kumar
 
The post release technologies of Crysis 3 (Slides Only) - Stewart Needham
The post release technologies of Crysis 3 (Slides Only) - Stewart NeedhamThe post release technologies of Crysis 3 (Slides Only) - Stewart Needham
The post release technologies of Crysis 3 (Slides Only) - Stewart NeedhamStewart Needham
 
Distribute Key Value Store
Distribute Key Value StoreDistribute Key Value Store
Distribute Key Value StoreSantal Li
 
Distribute key value_store
Distribute key value_storeDistribute key value_store
Distribute key value_storedrewz lin
 
Use perl creating web services with xml rpc
Use perl creating web services with xml rpcUse perl creating web services with xml rpc
Use perl creating web services with xml rpcJohnny Pork
 
Apache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra InternalsApache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra Internalsaaronmorton
 
WCF and WF in Framework 3.5
WCF and WF in Framework 3.5WCF and WF in Framework 3.5
WCF and WF in Framework 3.5ukdpe
 
Porting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustPorting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustEvan Chan
 
You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]
You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]
You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]Chris Suszyński
 
Porting is a Delicate Matter: Checking Far Manager under Linux
Porting is a Delicate Matter: Checking Far Manager under LinuxPorting is a Delicate Matter: Checking Far Manager under Linux
Porting is a Delicate Matter: Checking Far Manager under LinuxPVS-Studio
 
Kafka monitoring and metrics
Kafka monitoring and metricsKafka monitoring and metrics
Kafka monitoring and metricsTouraj Ebrahimi
 
Low latency microservices in java QCon New York 2016
Low latency microservices in java   QCon New York 2016Low latency microservices in java   QCon New York 2016
Low latency microservices in java QCon New York 2016Peter Lawrey
 
Learning spark ch10 - Spark Streaming
Learning spark ch10 - Spark StreamingLearning spark ch10 - Spark Streaming
Learning spark ch10 - Spark Streamingphanleson
 
Troubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issuesTroubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issuesMichael Klishin
 
Open Source XMPP for Cloud Services
Open Source XMPP for Cloud ServicesOpen Source XMPP for Cloud Services
Open Source XMPP for Cloud Servicesmattjive
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkESUG
 
Oracle Drivers configuration for High Availability
Oracle Drivers configuration for High AvailabilityOracle Drivers configuration for High Availability
Oracle Drivers configuration for High AvailabilityLudovico Caldara
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to ThriftDvir Volk
 

Similar to Kamaelia Protocol Walkthrough (20)

Cassandra 2.1 boot camp, Overview
Cassandra 2.1 boot camp, OverviewCassandra 2.1 boot camp, Overview
Cassandra 2.1 boot camp, Overview
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuning
 
The post release technologies of Crysis 3 (Slides Only) - Stewart Needham
The post release technologies of Crysis 3 (Slides Only) - Stewart NeedhamThe post release technologies of Crysis 3 (Slides Only) - Stewart Needham
The post release technologies of Crysis 3 (Slides Only) - Stewart Needham
 
Distribute Key Value Store
Distribute Key Value StoreDistribute Key Value Store
Distribute Key Value Store
 
Distribute key value_store
Distribute key value_storeDistribute key value_store
Distribute key value_store
 
Use perl creating web services with xml rpc
Use perl creating web services with xml rpcUse perl creating web services with xml rpc
Use perl creating web services with xml rpc
 
Apache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra InternalsApache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra Internals
 
WCF and WF in Framework 3.5
WCF and WF in Framework 3.5WCF and WF in Framework 3.5
WCF and WF in Framework 3.5
 
Porting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustPorting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to Rust
 
You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]
You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]
You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]
 
Porting is a Delicate Matter: Checking Far Manager under Linux
Porting is a Delicate Matter: Checking Far Manager under LinuxPorting is a Delicate Matter: Checking Far Manager under Linux
Porting is a Delicate Matter: Checking Far Manager under Linux
 
Kafka monitoring and metrics
Kafka monitoring and metricsKafka monitoring and metrics
Kafka monitoring and metrics
 
Low latency microservices in java QCon New York 2016
Low latency microservices in java   QCon New York 2016Low latency microservices in java   QCon New York 2016
Low latency microservices in java QCon New York 2016
 
Learning spark ch10 - Spark Streaming
Learning spark ch10 - Spark StreamingLearning spark ch10 - Spark Streaming
Learning spark ch10 - Spark Streaming
 
XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)
 
Troubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issuesTroubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issues
 
Open Source XMPP for Cloud Services
Open Source XMPP for Cloud ServicesOpen Source XMPP for Cloud Services
Open Source XMPP for Cloud Services
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
 
Oracle Drivers configuration for High Availability
Oracle Drivers configuration for High AvailabilityOracle Drivers configuration for High Availability
Oracle Drivers configuration for High Availability
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
 

More from kamaelian

Sharing Data and Services Safely in Concurrent Systems using Kamaelia
Sharing Data and Services Safely in Concurrent Systems using KamaeliaSharing Data and Services Safely in Concurrent Systems using Kamaelia
Sharing Data and Services Safely in Concurrent Systems using Kamaeliakamaelian
 
Sociable Software
Sociable SoftwareSociable Software
Sociable Softwarekamaelian
 
Open Source at the BBC: When, Why, Why not & How
Open Source at the BBC: When, Why, Why not & HowOpen Source at the BBC: When, Why, Why not & How
Open Source at the BBC: When, Why, Why not & Howkamaelian
 
Open Source at the BBC
Open Source at the BBCOpen Source at the BBC
Open Source at the BBCkamaelian
 
Kamaelia - Fave 2005
Kamaelia - Fave 2005Kamaelia - Fave 2005
Kamaelia - Fave 2005kamaelian
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parserkamaelian
 
Kamaelia - Networking Using Generators
Kamaelia - Networking Using GeneratorsKamaelia - Networking Using Generators
Kamaelia - Networking Using Generatorskamaelian
 
Scaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, GoalsScaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, Goalskamaelian
 
Kamaelia Internals
Kamaelia InternalsKamaelia Internals
Kamaelia Internalskamaelian
 
Building systems with Kamaelia
Building systems with KamaeliaBuilding systems with Kamaelia
Building systems with Kamaeliakamaelian
 
Free software: How does it work?
Free software: How does it work?Free software: How does it work?
Free software: How does it work?kamaelian
 

More from kamaelian (11)

Sharing Data and Services Safely in Concurrent Systems using Kamaelia
Sharing Data and Services Safely in Concurrent Systems using KamaeliaSharing Data and Services Safely in Concurrent Systems using Kamaelia
Sharing Data and Services Safely in Concurrent Systems using Kamaelia
 
Sociable Software
Sociable SoftwareSociable Software
Sociable Software
 
Open Source at the BBC: When, Why, Why not & How
Open Source at the BBC: When, Why, Why not & HowOpen Source at the BBC: When, Why, Why not & How
Open Source at the BBC: When, Why, Why not & How
 
Open Source at the BBC
Open Source at the BBCOpen Source at the BBC
Open Source at the BBC
 
Kamaelia - Fave 2005
Kamaelia - Fave 2005Kamaelia - Fave 2005
Kamaelia - Fave 2005
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parser
 
Kamaelia - Networking Using Generators
Kamaelia - Networking Using GeneratorsKamaelia - Networking Using Generators
Kamaelia - Networking Using Generators
 
Scaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, GoalsScaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, Goals
 
Kamaelia Internals
Kamaelia InternalsKamaelia Internals
Kamaelia Internals
 
Building systems with Kamaelia
Building systems with KamaeliaBuilding systems with Kamaelia
Building systems with Kamaelia
 
Free software: How does it work?
Free software: How does it work?Free software: How does it work?
Free software: How does it work?
 

Recently uploaded

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Kamaelia Protocol Walkthrough

  • 1. A walk through building & stacking protocols using Kamaelia Michael Sparks October 2008
  • 2. The aim of this document is to guide you through building a system where: ● A user connects to a server and ● Over a secure connection, ● Receives a sequence of JSON encode-able objects
  • 3. The aim of this document is to guide you through building a system where: ● A user connects to a server and ● Over a secure connection, This doc also uses speech ● Receives a sequence of JSON make “aside” bubbles like this to encode-able comments regarding particlar objects panels. You can skip these safely.
  • 4. ServerCore First of all, we start off with the ServerCore component. The hole is for fitting a protocol handler factory. eg a class, or function.
  • 5. ServerCore As an aside, this hole is pretty crucial. Without filling this hole, this component is pretty useless. So we call this sort of component a CHASSIS First of all, we start off with the ServerCore component. The hole is for fitting a protocol handler factory. eg a class, or function.
  • 6. ServerCore «factory» protocol So, we provide a protocol factory. ServerCore(protocol=protocol, port=2345)
  • 7. ServerCore «factory» protocol In retrospect, “protocol” as the name of an example protocol handler is a bad idea, so let's change this slightly. So, we provide a protocol factory. ServerCore(protocol=protocol, port=2345)
  • 8. ServerCore «factory» stackedjson So, we provide a protocol factory. ServerCore(protocol=stackedjson, port=2345)
  • 9. ServerCore «factory» stackedjson We then activate it, which causes it to start a subcomponent. ServerCore( .... )
  • 10. ServerCore TCPServer «factory» stackedjson We then activate it. It starts TCPServer subcomponent, which listens for connections. ServerCore( .... ).activate()
  • 11. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson A client then connects to the TCPServer which creates a ConnectedSocketAdapter to handle the mechanics of the connection.
  • 12. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson stackedjson TCPServer tells ServerCore it has done this. ServerCore in response calls the protocol factory to create a handler component...
  • 13. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson stackedjson ...which is wired up. The protocol handler just receives bytes and sends bytes, which are sent to the client via the ConnectedSocketAdapter
  • 14. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson stackedjson There, the key thing in creating a server, is to create an appropriate protocol handler component.
  • 15. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson stackedjson There, the key thing in creating a server, is to create an appropriate protocol handler component.
  • 16. stackedjson So, let's look inside this component
  • 17. stackedjson def protocol(*args,**argd): return Pipeline( PeriodicWakeup(message=quot;NEXTquot;, interval=1), Chooser(messages), MarshallJSON(), Encrypter(), DataChunker(), ) So, let's look inside this component
  • 18. stackedjson def protocol(*args,**argd): return Pipeline( PeriodicWakeup(message=quot;NEXTquot;, interval=1), Chooser(messages), MarshallJSON(), Encrypter(), DataChunker(), ) So, let's look inside this component. Clearly this is what actually handles the connection.
  • 19. PeriodicWakeup Chooser Pipeline( PeriodicWakeup(message=quot;NEXTquot;, MarshallJSON interval=1), Chooser(messages), Encrypter MarshallJSON(), Encrypter(), DataChunker DataChunker(), ) Let's expand that...
  • 20. PeriodicWakeup Chooser MarshallJSON Direction of Encrypter data flow DataChunker We see this is a uni-directional protocol – as soon as this pipeline starts up. Encrypted JSON data chunks get sent, ignoring client data.
  • 21. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Direction of Encrypter data flow Decrypter DataChunker DataDeChunker TCPClient So, given the ServerCore infrastructure means we can more or less ignore the network, what does the client side pipeline look like?
  • 22. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient Each component in the server, that is part of the user's protocol, has a matching component in the client.
  • 23. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient Fundamentally, this protocol allows one side of it to securely throw dictionary objects to clients which can then do something with them
  • 24. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient To understand what a client sees, we just look at these three components. The 2 highlighted server side components are the core behaviour.
  • 25. PeriodicWakeup Chooser ConsoleEchoer Let's rearrange these, showing the logical pipeline that drives what the user sees.
  • 26. PeriodicWakeup( PeriodicWakeup message=quot;NEXTquot;, interval=1) Chooser ConsoleEchoer First of all the PeriodicWakeupComponent sends out the message “NEXT” once per second.
  • 27. Messages = [ PeriodicWakeup {quot;helloquot;: quot;worldquot; }, {quot;helloquot;: [1,2,3] }, {quot;worldquot;: [1,2,3] }, {quot;worldquot;: {quot;gamequot;:quot;overquot;} }, Chooser ]*10 Chooser(messages) ConsoleEchoer These “NEXT” messages control the Chooser. The chooser steps through a list of messages, and when told “NEXT”, sends the next message.
  • 28. Messages = [ PeriodicWakeup {quot;helloquot;: quot;worldquot; }, {quot;helloquot;: [1,2,3] }, {quot;worldquot;: [1,2,3] }, It's worth noting that the Chooser Chooser can back backwards{quot;gamequot;:quot;overquot;} }, {quot;worldquot;: as well, just to ]*10 the start and end etc. For more Chooser(messages)at the docs :) details look ConsoleEchoer These “NEXT” messages control the Chooser. The chooser steps through a list of messages, and when told “NEXT”, sends the next message.
  • 29. PeriodicWakeup Chooser ConsoleEchoer(use_repr=True) ConsoleEchoer These messages arrive intact at the client - in this case a ConsoleEchoer. However it could be something more interesting – eg a game system.
  • 30. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient Going back to the overview slide, this diagram shows the various protocols which are stacked on top of each other.
  • 31. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient We have our core application protocol, stacked on top of a secure serialising communications channel. This truly is at the application level.
  • 32. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient We have our serialisation protocol. Clearly this is a message oriented protocol – it requires the lower layer to preserve boundaries.
  • 33. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient We have a secure transmission protocol. This is admittedly simplistic – it assumes predistributed keys. However it gives a flavour
  • 34. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient We then have our chunking protocol, which preserves message boundaries – necessary because TCP does not guarantee to do so.
  • 35. PeriodicWakeup Chooser ConsoleEchoer MarshallJSON DeMarshallJSON Encrypter Decrypter DataChunker DataDeChunker TCPClient So let's go back and see where these things fit back into the system.
  • 36. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson stackedjson So this is what we had ...
  • 37. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson stackedjson The client really looks like this... Also, this is a one way protocol
  • 38. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson The client really looks like this & this is a one way protocol. The protocol itself looks like this. And that's how those parts fit together.
  • 39. ServerCore Connected TCPServer SocketAdapter «factory» stackedjson So, finally, for completeness, we'll include the code.
  • 40. So, finally, for completeness, we'll include the code. Though, for code, this is a better location: http://tinyurl.com/4k3df2
  • 41. Bunch of imports... import cjson import Axon from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.Util.Chooser import Chooser from Kamaelia.Util.Console import ConsoleEchoer from Kamaelia.Internet.TCPClient import TCPClient from Kamaelia.Chassis.ConnectedServer import ServerCore from Kamaelia.Protocol.Framing import DataChunker, DataDeChunker from Kamaelia.Apps.Grey.PeriodicWakeup import PeriodicWakeup from Crypto.Cipher import DES
  • 42. Define the messages being slung to clients messages = [ {quot;helloquot;: quot;worldquot; }, {quot;helloquot;: [1,2,3] }, {quot;worldquot;: [1,2,3] }, {quot;worldquot;: {quot;gamequot;:quot;overquot;} }, ]*10
  • 43. Then the JSON De/Marshalling components class MarshallJSON(Axon.Component.component): def main(self): while not self.dataReady(quot;controlquot;): for j in self.Inbox(quot;inboxquot;): j_encoded = cjson.encode(j) self.send(j_encoded, quot;outboxquot;) if not self.anyReady(): self.pause() yield 1 class DeMarshallJSON(Axon.Component.component): def main(self): while not self.dataReady(quot;controlquot;): for j in self.Inbox(quot;inboxquot;): j_decoded = cjson.decode(j) self.send(j_decoded, quot;outboxquot;) if not self.anyReady(): self.pause() yield 1
  • 44. Define our encoding layer using normal code...1 class Encoder(object): quot;quot;quot;Null encoder/base encoder - returns the same string for encode/decodequot;quot;quot; def __init__(self, key, **argd): super(Encoder, self).__init__(**argd) self.__dict__.update(argd) self.key = key def encode(self, some_string): return some_string def decode(self, some_string): return some_string
  • 45. Define our encoding layer using normal code...2 class DES_CRYPT(Encoder): def __init__(self, key, **argd): super(DES_CRYPT, self).__init__(key, **argd) self.key = self.pad_eight(key)[:8] self.obj = obj=DES.new(self.key, DES.MODE_ECB) def encode(self, some_string): padded = self.pad_eight(some_string) encrypted = self.obj.encrypt(padded) return encrypted def decode(self, some_string): padded = self.obj.decrypt(some_string) decoded = self.unpad(padded) return decoded # ... continued
  • 46. Define our encoding layer using normal code...3 # class DES_CRYPT(Encoder): # ... continued from before def pad_eight(self, some_string): X = len(some_string) if X % 8 != 0: pad_needed = 8-X % 8 else: pad_needed = 8 pad_needed = 8-(X % 8) PAD = pad_needed * chr(pad_needed) return some_string+PAD def unpad(self, some_string): x = ord(some_string[-1]) return some_string[:-x]
  • 47. Create Encryption components using this class Encrypter(Axon.Component.component): key = quot;ABCDquot; def main(self): crypter = DES_CRYPT(self.key) while not self.dataReady(quot;controlquot;): for j in self.Inbox(quot;inboxquot;): j_encoded = crypter.encode(j) self.send(j_encoded, quot;outboxquot;) if not self.anyReady(): self.pause() yield 1 Note, this is not a serious protocol, it is an illustration. This form of pre-shared key would be a bad idea, but the pattern of usage will be useful.
  • 48. Create Decryption components using this class Decrypter(Axon.Component.component): key = quot;ABCDquot; def main(self): crypter = DES_CRYPT(self.key) while not self.dataReady(quot;controlquot;): for j in self.Inbox(quot;inboxquot;): j_decoded = crypter.decode(j) self.send(j_decoded, quot;outboxquot;) if not self.anyReady(): self.pause() yield 1 Note, this is not a serious protocol, it is an illustration. This form of pre-shared key would be a bad idea, but the pattern of usage will be useful.
  • 49. Create the protocol handler factory & Client def stackedjson(*args,**argd): return Pipeline( PeriodicWakeup(message=quot;NEXTquot;, interval=1), Chooser(messages), MarshallJSON(), Encrypter(), # Encrypt on the way out DataChunker(), ) def json_client_prefab(ip, port): return Pipeline( TCPClient(ip, port=port), DataDeChunker(), Decrypter(), # Decrypt on the way in DeMarshallJSON(), ConsoleEchoer(use_repr=True) )
  • 50. And finally start the server and point a client at the server. ServerCore(protocol=protocol, port=2345).activate() json_client_prefab(quot;127.0.0.1quot;, 2345).run() ServerCore Connected TCPServer SocketAdapter «factory» stackedjson