Ejemplo n.º 1
0
 def __init__(self):
     self.getOptions()
     self.ip = getIP()[0]
     self.logger = loadComponent('plugin', 'Logger')(name='upnp')
     self.log = self.logger.getLoggerChild('pforwarding')
     self.upnp = loadComponent('plugin', 'UPNP')(self)
     self.upnp.startUpnp(self.ip, self.proto)
Ejemplo n.º 2
0
    def initEngine(self, *args, **kwargs):
        self.log.info('initing client')
        self.enableTraffic(cPipe=kwargs['cPipe'])
        self.enableUI(**kwargs)
        self.messages = []
        self.sidListeners = []
        self.checkServers={}
        self.streamListeners=[]
        self.waitingReply=[]
        self.converters={}

        if 'basic' in kwargs and kwargs['basic']:
            self.basic=True
        else:
            self.basic=False
            self.holePuncher=loadComponent('plugin','HolePuncher')(_parent=self)
            self.useHolePunching=True
            self.rProducerInf=loadComponent('plugin','RemoteProducerController')(_parent=self)
        self.chatClient=loadComponent('plugin','ChatClient')(_parent=self)

        sip=None
        sport=None
        if 'vizir' in kwargs['interface'][2].keys() and kwargs['interface'][2]['vizir']:
            sip=kwargs['interface'][2]['vizirIP']
            sport=kwargs['interface'][2]['vizirPort']
        self.netChecker=loadComponent('plugin','NetworkChecker')(sip,sport,_parent=self,)
        reactor.callLater(0.2,self.interface.checkNetwork)
Ejemplo n.º 3
0
 def initElement(self, port=30000, to='dataPort', **kwargs):
     self.log.info('BoraElement loaded')
     self.to = to
     self.port = port
     self.schedulers = {}
     flowControl = loadComponent('flowcontrol', 'DistFlowControl')
     self.flowControl = flowControl(_parent=self)
     reactor.addSystemEventTrigger('before', 'shutdown', bora.die)
Ejemplo n.º 4
0
    def initUI(self, port=9000, testbed=False):
        xmlrpc.XMLRPC.__init__(self)
        print 'start listening xmlrpc'
        reactor.listenTCP(port, server.Site(self))
        self.proxy = None
        self.remote = True

        self.vizInterface = loadComponent('plugin',
                                          'VizXMLInterface')(_parent=self)
        self.vizPlot = loadComponent('plugin', 'OverlayViz')()
        self.logger = loadComponent('plugin',
                                    'VizirLoggerGui')(_parent=self,
                                                      testbed=testbed)
        self.statsController = vizirStats(_parent=self)
        self.statsGui = None
        # self.plotter=loadComponent('plugin','VizirPlotter')(_parent=self)
        self.constructGui()
Ejemplo n.º 5
0
Archivo: core.py Proyecto: loox-/p2ner
    def initOverlay(self, producer, stream):
        self.log = self.logger.getLoggerChild(('s' + str(stream.id)),
                                              self.interface)
        self.log.info('initing overlay')
        self.overlay = self
        self.sanityCheck(["controlPipe", "overlay"])
        self.registerMessages()
        self.maxPeers = stream.overlay['numNeigh'] / 2
        self.producer = producer
        self.stream = stream
        #self.producerNeighbours = []
        self.neighbourhoods = {}

        if self.drawPlots:
            self.vizInterface = loadComponent('plugin',
                                              'VizNetInterface')(_parent=self)
            self.vizPlot = loadComponent('plugin', 'OverlayViz')()
            self.vizPlot.start(self.vizInterface)
Ejemplo n.º 6
0
    def enableUI(self, **kwargs):
        if 'UI' not in kwargs or not kwargs['UI']:
            return

        controlUI = kwargs['UI']
        c, a, k = controlUI
        self.log.debug('trying to load %s', c)
        controlUI = loadComponent('ui', c)
        self.controlUI = controlUI(
            remote=False,
            _parent=self.interface)  # (_parent=self, *a, **{'remote':False})
Ejemplo n.º 7
0
    def newSubStream(self,stream,id,output):
        self.waitingReply.remove(id)
        if stream!=-1:
            s, a, k = ('StreamClient',[],{})
            self.log.debug('trying to load %s',s)
            streamComponent = loadComponent("stream", s)
            k['stream']=stream
            if output:
                k['output']=(output['comp'],[],{'output':output['kwargs']})

            self.streams.append(streamComponent( _parent=self,**k))
        self.interface.returnSubStream(stream,id)
Ejemplo n.º 8
0
Archivo: core.py Proyecto: loox-/p2ner
 def initStream(
     self, *args, **kwargs
 ):  #stream, scheduler=defaultScheduler, overlay=defaultOverlay,producer=False):
     self.producing = False
     self.running = False
     self.log = self.logger.getLoggerChild(('c' + str(self.stream.id)),
                                           self.interface)
     self.log.info('new  stream')
     self.log.info('%s', self.stream)
     self.sanityCheck(["trafficPipe", "controlPipe", "output"])
     c, a, k = defaultOverlay
     if self.stream.overlay:
         c = self.stream.overlay['component']
     self.log.debug('trying to load %s', c)
     self.overlay = loadComponent("overlay", c)(_parent=self, *a, **k)
     c, a, k = defaultScheduler
     if self.stream.scheduler:
         c = self.stream.scheduler['component']
     self.log.debug('trying to load %s', c)
     self.scheduler = loadComponent("scheduler", c)(_parent=self, *a, **k)
     self.trafficPipe.registerProducer(self.scheduler)
     self.registerMessages()
Ejemplo n.º 9
0
    def __init__(self, *args, **kwargs):
        self.streamComponent = self
        if 'stream' in kwargs:
            self.stream = kwargs['stream']
        else:
            raise ValueError('you definetely need a stream')

        self.server = Peer(self.stream.server[0], self.stream.server[1])
        output = defaultOutput
        if "output" in kwargs:
            output = kwargs["output"]
        c, a, k = output
        self.log.debug('trying to load %s', c)
        output = loadComponent("output", c)
        self.output = output(_parent=self, *a, **k)
        if "input" in kwargs:
            c, a, k = kwargs["input"]
            self.log.debug('trying to load %s', c)
            input = loadComponent("input", c)
            self.input = input(_parent=self, *a, **k)

        self.initStream(*args, **kwargs)
Ejemplo n.º 10
0
    def newStream(self, stream,input,output):
        if self.getPStream(stream.id):
            self.log.error('stream with id %d already exists',stream.id)
            raise ValueError("Stream already exists")
        s, a, k = ('StreamProducer',[],{})

        self.log.debug('trying to load %s',s)
        streamComponent = loadComponent("stream", s)
        k['stream']=stream
        if input:
            k['input']=(input['component'],[],{'input':input})
        if output:
            k['output']=(output['comp'],[],{'output':output['kwargs']})

        self.producingStreams.append(streamComponent( _parent=self,**k))
Ejemplo n.º 11
0
    def checkUPNP(self):
        self.log.info('trying upnp')

        valid = self.preferences.getUPNP()
        if not valid or self.upnpDevice:
            self.log.info('upnp is deactivated')
            self.checkStun()
            return

        self.upnpDevice = loadComponent('plugin',
                                        "miniUPNP")(self.controlPort,
                                                    self.dataPort, self.log)
        d = deferToThread(self.upnpDevice.start)
        #d=self.upnpDevice.start()
        d.addCallback(self.upnpSuccess)
        d.addErrback(self.upnpFailed)
Ejemplo n.º 12
0
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from p2ner.base import *
import p2ner.abstract.engine
import p2ner.base.messages.bootstrap, twisted.application.internet, twisted.web.xmlrpc
from p2ner.core.components import getComponents, _entry_points, loadComponent
import weakref, twisted.internet, bitarray, construct
Server = loadComponent("engine", "Server")
from twisted.internet import reactor
P2NER = Server(_parent=None,
               control=("UDPCM", [], {
                   "port": 16000
               }),
               logger=('Logger', {
                   'name': 'p2nerServer',
                   'server': True
               }),
               interface=('NullControl', [], {}))
reactor.run()
Ejemplo n.º 13
0
# -*- coding: utf-8 -*-
#   Copyright 2012 Loris Corazza, Sakis Christakidis
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


from p2ner.base import *
import p2ner.abstract.engine
import subprocess
import p2ner.base.messages.bootstrap, twisted.application.internet, twisted.web.xmlrpc
from p2ner.core.components import getComponents, _entry_points, loadComponent
import weakref, twisted.internet, bitarray, construct
Client = loadComponent("engine", "ComboClient")
from twisted.internet import reactor
P2NER = Client(_parent=None,UI=('GtkGui',[],{}),basic=True)
reactor.run()  
Ejemplo n.º 14
0
 def startBWMeasurement(self,ip,gui=None,defer=None):
     loadComponent('plugin','TCPBandwidthClient')(ip,gui,defer).start()
Ejemplo n.º 15
0
 def startConverting(self,dir,filename,videorate,subs,subsFile,subsEnc):
     id=len(self.converters.keys())
     self.converters[id]=loadComponent('plugin','Converter')()
     self.converters[id].startConverting(dir,filename,videorate,subs,subsFile,subsEnc)
     return id
Ejemplo n.º 16
0
    def __init__(self, *args, **kwargs):

        self.useHolePunching = False
        self.streams = []
        self.producingStreams = []
        self.__stats__ = []

        ##INTERFACE
        interface = defaultInterface
        if "interface" in kwargs:
            interface = kwargs['interface']

        c, a, k = interface
        print c
        interface = loadComponent('interface', c)
        self.interface = interface(_parent=self, *a, **k)
        self.interface.start()

        ##LOGGER
        if 'logger' not in kwargs:
            logger = defaultLogger
        else:
            logger = kwargs['logger']
        c, k = logger
        self.logger = loadComponent('plugin', c)(**k)
        self.log = self.logger.getLoggerChild('base', interface=self.interface)

        ##Preferences
        self.preferences = Preferences(_parent=self)
        self.preferences.start()

        self.controlPipe = Pipeline(_parent=self)

        self.log.debug('trying to load pipeline element messageparser')
        mparser = loadComponent(
            "pipeelement", "MessageParserElement")(_parent=self.controlPipe)

        self.log.debug('trying to load pipeline element multiReceipient')
        multiparser = loadComponent(
            "pipeelement", "MultiRecipientElement")(_parent=self.controlPipe)

        self.log.debug('trying to load pipeline element ack')
        ackparser = loadComponent("pipeelement",
                                  "AckElement")(_parent=self.controlPipe)

        self.log.debug('trying to load pipeline element headerparser')
        hparser = loadComponent(
            "pipeelement", "HeaderParserElement")(_parent=self.controlPipe)

        self.log.debug('trying to load pipeline element controlbandwidth')
        bw = loadComponent("pipeelement",
                           "UDPBandwidthElement")(_parent=self.controlPipe)

        if "control" not in kwargs:
            control = defaultControl
        else:
            control = kwargs["control"]
        c, a, k = control
        p = 50000
        if "port" in kwargs:
            p = kwargs["port"]

        port, IF = p, ""
        if "port" in k:
            port = k["port"]
        if "interface" in k:
            IF = k["interface"]

        k['port'] = findNextConsecutivePorts(port, IF)
        port = k['port']

        self.log.debug('trying to load pipeline element updport')
        udpparser = loadComponent("pipeelement",
                                  "UDPPortElement")(_parent=self.controlPipe,
                                                    *a,
                                                    **k)

        self.controlPipe.append(mparser)
        self.controlPipe.append(multiparser)
        self.controlPipe.append(ackparser)
        self.controlPipe.append(hparser)
        self.controlPipe.append(bw)
        self.controlPipe.append(udpparser)

        #self.controlPipe.printall()
        #self.controlPipe.call('listen')

        ##TEMPORARY LOAD STATS
        stats = self.preferences.getActiveStats()
        for s in stats:
            s[1]['port'] = port
            self.__stats__.append(
                loadComponent("stats", s[0])(_parent=self, **s[1]))

        if 'stats' in kwargs:
            stats = kwargs['stats']
            self.__stats__.append(
                loadComponent("stats", stats)(_parent=self, **{
                    'port': port
                }))

        self.initEngine(*args, **kwargs)
Ejemplo n.º 17
0
    def enableTraffic(self, **kwargs):
        ##NetworkChecker
        #self.netChecker=loadComponent('plugin','NetworkChecker')(_parent=self)
        #self.holePuncher=loadComponent('plugin','HolePuncher')(_parent=self)

        if 'cPipe' not in kwargs.keys():
            cPipe = False
            print 'no cPipe in kwargs'
            print kwargs
        else:
            cPipe = kwargs['cPipe']

        self.trafficPipe = Pipeline(_parent=self)
        if not cPipe:
            print 'loading normal traffic Pipe'
            self.log.debug('trying to load pipeline element blocksplitter')
            bsplitter = loadComponent(
                "pipeelement",
                "BlockSplitterElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(bsplitter)

            self.log.debug('trying to load pipeline element blockcache')
            bcache = loadComponent(
                "pipeelement", "BlockCacheElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(bcache)

            self.log.debug('trying to load pipeline element flowcontrol')
            fcontrol = loadComponent(
                "pipeelement", "FlowControlElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(fcontrol)

            self.log.debug('trying to load pipeline element blockheader')
            bhead = loadComponent(
                "pipeelement", "BlockHeaderElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(bhead)

            #self.log.debug('trying to load pipeline element bandwidth')
            #bwid = loadComponent("pipeelement", "BandwidthElement")(_parent=self.controlPipe)
            #self.trafficPipe.append(bwid)

            self.log.debug('trying to load pipeline element bandwidth')
            bwid = loadComponent("pipeelement",
                                 "BandwidthElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(bwid)

            self.log.debug('trying to load pipeline element udpport')
            port = self.controlPipe.getElement("UDPPortElement").port + 1
            tport = loadComponent("pipeelement",
                                  "UDPPortElement")(_parent=self.trafficPipe,
                                                    to='dataPort',
                                                    port=port)
            self.trafficPipe.append(tport)
        else:
            print 'loading cPipe'

            self.log.debug('trying to load pipeline element messageparser')
            mparser = loadComponent(
                "pipeelement",
                "MessageParserElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(mparser)

            self.log.debug('trying to load pipeline element multiReceipient')
            multiparser = loadComponent(
                "pipeelement",
                "MultiRecipientElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(multiparser)

            self.log.debug('trying to load pipeline element ack')
            ackparser = loadComponent("pipeelement",
                                      "AckElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(ackparser)

            self.log.debug('trying to load pipeline element headerparser')
            hparser = loadComponent(
                "pipeelement", "HeaderParserElement")(_parent=self.trafficPipe)
            self.trafficPipe.append(hparser)

            self.log.debug('trying to load pipeline element bora')
            port = self.controlPipe.getElement("UDPPortElement").port + 1
            bora = loadComponent("pipeelement",
                                 "BoraElement")(_parent=self.trafficPipe,
                                                to='dataPort',
                                                port=port)
            self.trafficPipe.append(bora)
Ejemplo n.º 18
0
# -*- coding: utf-8 -*-
#   Copyright 2012 Loris Corazza, Sakis Christakidis
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from p2ner.base import *
import p2ner.abstract.engine
import subprocess
import p2ner.base.messages.bootstrap, twisted.application.internet, twisted.web.xmlrpc
from p2ner.core.components import getComponents, _entry_points, loadComponent
import weakref, twisted.internet, bitarray, construct
Client = loadComponent("ui", "GtkGui")
from twisted.internet import reactor
P2NER = Client()
reactor.run()