I just thought I would see how small I could make a Freenet client without
using any of the existing Freenet classes. It's a half hour hack, so enjoy :-).

I don't think it handles binary data correctly.

import java.io.*;
import java.net.Socket;
import java.net.InetAddress;
import java.util.Random;
import java.security.MessageDigest;
public class Tiny {
    public static void main(String[] args) {
        try {
            Socket s = new 
Socket(InetAddress.getByName(args[0]),Integer.parseInt(args[1]));
            Random r = new Random();
            MessageDigest md = MessageDigest.getInstance("SHA");
            for (int i = 0; i < args[2].length() ; i++) {md.update((byte) 
args[2].charAt(i));}
            byte[] bs = md.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0 ; i < 20 ; i++) {
                int c1,c2;
                c1 = ((bs[i] >>> 4) & 0xf);
                c2 = (bs[i] & 0xf);
                sb.append((char)((c1 > 9) ? 'A' + (c1 - 10) : '0' + c1));
                sb.append((char) ((c2 > 9) ? 'A' + (c2 - 10) : '0' + c2));
            }
            PrintWriter pr = new PrintWriter(s.getOutputStream());
            pr.print("DataRequest\nHopsToLive=5\nUniqueID=" + 
Long.toHexString(r.nextLong()) + "\nDepth=" + r.nextLong() % 10 +5 + 
"\nSearchKey=" + sb.toString() + "\nEndMessage\n");
            pr.flush();
            BufferedReader br = new BufferedReader(new 
InputStreamReader(s.getInputStream()));
            String st = null;
            do {
                st = br.readLine();
                if (st.equals("EndMessage"))
                    System.exit(1);
            } while (!st.equals("Data"));
            int i;
            while ((i = br.read()) != -1) {
                System.out.print((char) i);
            }
        } catch (Exception e) {
            System.out.println("Oskar's very small request client\nUsage: Tiny 
<address> <port> <key>");
        }
    }
}

-- 

Oskar Sandberg

md98-osa at nada.kth.se

#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)

_______________________________________________
Freenet-dev mailing list
Freenet-dev at lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/freenet-dev

Reply via email to