From a8077558941d092720d0fc0062ce94515615f83f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=96man?= <andreas@lonelycoder.com>
Date: Sat, 17 May 2008 08:14:37 +0000
Subject: [PATCH] Use suggested cluster size

---
 cwc.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/cwc.c b/cwc.c
index caebf869..14776c26 100644
--- a/cwc.c
+++ b/cwc.c
@@ -101,9 +101,8 @@ typedef struct cwc_transport {
 
   void *ct_keys;
 
-#define CT_CLUSTER_SIZE 32
-
-  uint8_t ct_tsbcluster[188 * CT_CLUSTER_SIZE];
+  int ct_cluster_size;
+  uint8_t *ct_tsbcluster;
   int ct_fill;
 
 } cwc_transport_t;
@@ -687,13 +686,13 @@ cwc_descramble(th_descrambler_t *td, th_transport_t *t, struct th_stream *st,
   memcpy(ct->ct_tsbcluster + ct->ct_fill * 188, tsb, 188);
   ct->ct_fill++;
 
-  if(ct->ct_fill != CT_CLUSTER_SIZE)
+  if(ct->ct_fill != ct->ct_cluster_size)
     return 0;
 
   ct->ct_fill = 0;
 
   vec[0] = ct->ct_tsbcluster;
-  vec[1] = ct->ct_tsbcluster + CT_CLUSTER_SIZE * 188;
+  vec[1] = ct->ct_tsbcluster + ct->ct_cluster_size * 188;
   vec[2] = NULL;
 
   while(1) {
@@ -722,6 +721,7 @@ cwc_transport_destroy(cwc_transport_t *ct)
   LIST_REMOVE(ct, ct_cwc_link);
 
   free_key_struct(ct->ct_keys);
+  free(ct->ct_tsbcluster);
   free(ct);
 }
 
@@ -758,6 +758,9 @@ cwc_transport_start(th_transport_t *t)
       continue;
 
     ct = calloc(1, sizeof(cwc_transport_t));
+    ct->ct_cluster_size = get_suggested_cluster_size();
+    ct->ct_tsbcluster = malloc(ct->ct_cluster_size * 188);
+
     ct->ct_keys = get_key_struct();
     ct->ct_cwc = cwc;
     ct->ct_transport = t;