Browse Source

Changed from MD5 to CRC16

master
Stephen Downward 2 years ago
parent
commit
4c657a6be3
2 changed files with 8 additions and 6 deletions
  1. +7
    -5
      ax26/classes.py
  2. +1
    -1
      setup.py

+ 7
- 5
ax26/classes.py View File

@@ -1,5 +1,5 @@
import gzip
import hashlib
import crcmod
import time
from threading import Thread

@@ -28,6 +28,8 @@ class Ax26:
self.send_timeout_seconds = 10
self.receive_timeout_seconds = 10 #Between chunks

self._crc = crcmod.mkCrcFun(0x18005, rev=False, initCrc=0xFFFF, xorOut=0x0000)


read_thread = Thread(target=self._read_thread)#Start reader thread
read_thread.daemon = True
@@ -91,7 +93,7 @@ class Ax26:
if first_byte is not None:
recvd_packet = True
(chunk, checksum) = first_byte.rsplit(const.CHECKSUM, 1)
if checksum == hashlib.md5(chunk).hexdigest().encode():
if checksum == str(self._crc(chunk)).encode():
fulldata += chunk
self._write(dest_filter[0], src_filter[0], const.ACK) # Have to be len of 1 if first_byte not None
else:
@@ -122,7 +124,7 @@ class Ax26:
start_time = time.time()
(chunk, checksum) = body.rsplit(const.CHECKSUM, 1)
# print(chunk) # DEBUGGING
if checksum == hashlib.md5(chunk).hexdigest().encode():
if checksum == str(self._crc(chunk)).encode():
fulldata += chunk
# print(chunk) # DEBUGGING
# Request next
@@ -138,7 +140,7 @@ class Ax26:
def _raw_send_data(self, data, src, dest): # TODO: PACKET IDs

# 32 for MD5. 3 for byte delimiters
max_data_chunk_length = self.max_packet_length - (len(src) + len(dest) + 35)
max_data_chunk_length = self.max_packet_length - (len(src) + len(dest) + 16)

# print(gzip.compress(data, 9)) # DEBUGGING
data = util.escape_data(gzip.compress(data, 9)) + const.DATA_END # Compress data and add DATA_END byte
@@ -152,7 +154,7 @@ class Ax26:

self._k.write(util.format_header(src, dest) + sep_byte +
data[0:max_data_chunk_length] + const.CHECKSUM +
hashlib.md5(data[0:max_data_chunk_length]).hexdigest().encode())
str(self._crc(data[0:max_data_chunk_length])).encode())
sep_byte = const.DATA_CHUNK
# print(html[0:packet_length]) #DEBUGGING
ack = False # Wait for client to acknowledge packet, or resend


+ 1
- 1
setup.py View File

@@ -2,7 +2,7 @@ from distutils.core import setup
setup(
name = 'ax26',
packages = ['ax26'],
version = '0.25',
version = '0.3',
description = 'AX26 Client/Server library in Python.',
author = 'Stephen Downward',
author_email = 'stephen@stephendownward.ca',


Loading…
Cancel
Save