def frecv(self):
     data, serviceName = self.mrecv(1024)
     if not data:
         return None, None
     file = FileMessage()
     file.decodeFileMessage(data)
     if serviceName != 'file':
         print('Bad file service name', file.serviceName)
         return None, None
     return file.headers, file.data
Esempio n. 2
0
 def frecv(self):
   data, serviceName=self.mrecv(1024)
   if not data:
     return None, None
   file=FileMessage()
   file.decodeFileMessage(data)
   if serviceName!='file':
     print('Bad file service name', file.serviceName)
     return None, None
   return file.headers, file.data
Esempio n. 3
0
  def getMeta(self, msock, headers, data, addr):
    print('getMeta')
    file=headers['file']

    result={'command': 'putMeta', 'file': file}
    result['length']=os.path.getsize(self.config['root']+'/'+file)

    fmsg=FileMessage()
    fmsg.createFileMessage(result, None)

    msock.msendto(fmsg.message, addr, service='file')
Esempio n. 4
0
    def getMeta(self, msock, headers, data, addr):
        print('getMeta')
        file = headers['file']

        result = {'command': 'putMeta', 'file': file}
        result['length'] = os.path.getsize(self.config['root'] + '/' + file)

        fmsg = FileMessage()
        fmsg.createFileMessage(result, None)

        msock.msendto(fmsg.message, addr, service='file')
Esempio n. 5
0
  def handle(self, msock, msg, addr):
    print('-----------------')
    print(msg.decode('ascii'))

    fmsg=FileMessage()
    fmsg.decodeFileMessage(msg)
    cmd=fmsg.headers['command']
    if cmd in self.commands:
      f=self.commands[cmd]
      f(msock, fmsg.headers, fmsg.data, addr)
    else:
      print('Unknown file command', cmd)
      return
Esempio n. 6
0
    def handle(self, msock, msg, addr):
        print('-----------------')
        print(msg.decode('ascii'))

        fmsg = FileMessage()
        fmsg.decodeFileMessage(msg)
        cmd = fmsg.headers['command']
        if cmd in self.commands:
            f = self.commands[cmd]
            f(msock, fmsg.headers, fmsg.data, addr)
        else:
            print('Unknown file command', cmd)
            return
Esempio n. 7
0
  def get(self, msock, headers, data, addr):
    file=headers['file']
    offset=headers['offset']

    f=open(self.config['root']+'/'+file, 'rb')
    f.seek(offset)
    bs=f.read(self.blockSize)
    f.close()

    result={'command': 'put', 'file': file, 'offset': offset}

    fmsg=FileMessage()
    fmsg.createFileMessage(result, bs)

    msock.msendto(fmsg.message, addr, service='file')
Esempio n. 8
0
    def get(self, msock, headers, data, addr):
        file = headers['file']
        offset = headers['offset']

        f = open(self.config['root'] + '/' + file, 'rb')
        f.seek(offset)
        bs = f.read(self.blockSize)
        f.close()

        result = {'command': 'put', 'file': file, 'offset': offset}

        fmsg = FileMessage()
        fmsg.createFileMessage(result, bs)

        msock.msendto(fmsg.message, addr, service='file')
Esempio n. 9
0
 def fsend(self, headers, data):
   fmsg=FileMessage()
   fmsg.createFileMessage(headers, data)
   self.msend(fmsg.message, service='file')
Esempio n. 10
0
 def fsendto(self, headers, data, addr):
   file=FileMessage()
   file.createFileMessage(headers, data)
   self.msendto(file.message, addr)
 def fsend(self, headers, data):
     fmsg = FileMessage()
     fmsg.createFileMessage(headers, data)
     self.msend(fmsg.message, service='file')
 def fsendto(self, headers, data, addr):
     file = FileMessage()
     file.createFileMessage(headers, data)
     self.msendto(file.message, addr)