tachang/EyeFiServer — Issue #4: EyeFi Card may timeout with EyeFiServer on slow machine
Author: nandff
Created: 2012-01-27 03:29:42+00:00
State: open

EyeFiServer on a slow machine (NetBSD/i386,Atom(TM) CPU 330 @ 1.60GHz) makes EyeFi Card timeout, and a file transfers many times repeatedly.

The following patch solves the problem for me.

thanks,

A patch for faster TCPChecksum calculation:
*** tachang-EyeFiServer-4c473e7/Release 2.0/EyeFiCrypto.py	Sun Feb 28 12:47:58 2010
--- ../EyeFiServer/Release 2.0/EyeFiCrypto.py	Mon Jan 9 18:27:25 2012
***************
*** 2,7 ****
--- 2,8 ----
import struct
import array
import hashlib
+ import sys

class EyeFiCrypto():

***************
*** 15,76 ****
if(len(bytes) % 2 != 0 ):
bytes = bytes + "\x00"

! counter = 0
! sumOfTwoByteWords = 0
!
! # Loop over all the bytes, two at a time
! while(counter < len(bytes) ):
!
! # For each pair of bytes, cast them into a 2 byte integer (unsigned short)
! # Compute using little-endian (which is what the '<' sign if for)
! unsignedShort = struct.unpack("> 16):
! sumOfTwoByteWords = (sumOfTwoByteWords >> 16) + (sumOfTwoByteWords & 0xFFFF)

# Take the one's complement of the result through the use of an xor
! checksum = sumOfTwoByteWords ^ 0xFFFFFFFF
!
! # Compute the final checksum by taking only the last 16 bits
! checksum = (checksum & 0xFFFF)
!
return checksum
-

def calculateIntegrityDigest(self, bytes, uploadkey):

- # If the number of bytes I was given is not a multiple of 512
- # pad the input with a null characters to get the proper alignment
- while(len(bytes) % 512 != 0 ):
- bytes = bytes + "\x00"
-
counter = 0

# Create an array of 2 byte integers
concatenatedTCPChecksums = array.array('H')

# Loop over all the bytes, using 512 byte blocks
! while(counter < len(bytes) ):
!
tcpChecksum = self.calculateTCPChecksum(bytes[counter:counter+512])
concatenatedTCPChecksums.append(tcpChecksum)
counter = counter + 512
!
! # Append the upload key
! concatenatedTCPChecksums.fromstring(binascii.unhexlify(uploadkey))

# Get the concatenatedTCPChecksums array as a binary string
integrityDigest = concatenatedTCPChecksums.tostring()
!
# MD5 hash the binary string
m = hashlib.md5()
m.update(integrityDigest)
--- 16,61 ----
if(len(bytes) % 2 != 0 ):
bytes = bytes + "\x00"

! ushorts = array.array('H', bytes)
! if sys.byteorder == "big":
! ushorts.byteswap()
! sumOfTwoByteWords = sum(ushorts)

# The sum at this point is probably a 32 bit integer. Take the left 16 bits
# and the right 16 bites, interpret both as an integer of max value 2^16 and
# add them together. If the resulting value is still bigger than 2^16 then do it
# again until we get a value less than 16 bits.
! sumOfTwoByteWords = (sumOfTwoByteWords >> 16) + (sumOfTwoByteWords & 0xFFFF)
! sumOfTwoByteWords = (sumOfTwoByteWords >> 16) + (sumOfTwoByteWords & 0xFFFF)

# Take the one's complement of the result through the use of an xor
! checksum = sumOfTwoByteWords ^ 0xFFFF
return checksum

def calculateIntegrityDigest(self, bytes, uploadkey):

counter = 0

# Create an array of 2 byte integers
concatenatedTCPChecksums = array.array('H')

# Loop over all the bytes, using 512 byte blocks
! while counter <= len(bytes) - 512:
tcpChecksum = self.calculateTCPChecksum(bytes[counter:counter+512])
concatenatedTCPChecksums.append(tcpChecksum)
counter = counter + 512
! if counter < len(bytes):
! tcpChecksum = self.calculateTCPChecksum(bytes[counter:])
! concatenatedTCPChecksums.append(tcpChecksum)

# Get the concatenatedTCPChecksums array as a binary string
+ if sys.byteorder == "big":
+ concatenatedTCPChecksums.byteswap()
integrityDigest = concatenatedTCPChecksums.tostring()
!
! # Append the upload key
! integrityDigest += binascii.unhexlify(uploadkey)
!
# MD5 hash the binary string
m = hashlib.md5()
m.update(integrityDigest)