func (codecType stringCodecType) NewCodec(r io.Reader, w io.Writer) Codec { return stringCodec{ codecType.Spliter, binary.NewReader(r), binary.NewWriter(w), } }
// Do DH64 key exchange and return a RC4 reader. func conn_init(conn net.Conn) (*binary.Writer, *binary.Reader, error) { var ( writer = binary.NewWriter(conn) reader = binary.NewReader(conn) ) rand.Seed(time.Now().UnixNano()) privateKey, publicKey := dh64.KeyPair() log.Print("server public key: ", publicKey) writer.WriteUint64LE(publicKey) if writer.Error() != nil { return nil, nil, writer.Error() } clientPublicKey := reader.ReadUint64LE() if reader.Error() != nil { return nil, nil, reader.Error() } log.Print("client public key: ", clientPublicKey) secert := dh64.Secret(privateKey, clientPublicKey) log.Print("secert: ", secert) key := make([]byte, 8) binary.PutUint64LE(key, secert) rc4stream, err := rc4.NewCipher(key) if err != nil { return nil, nil, err } log.Print("key: ", hex.EncodeToString(key)) reader = binary.NewReader(cipher.StreamReader{ R: conn, S: rc4stream, }) return writer, reader, nil }
func (codecType stringCodecType) NewDecoder(r io.Reader) Decoder { return stringDecoder{ codecType.Spliter, binary.NewReader(r), } }
func (_ selfCodecType) NewDecoder(r io.Reader) Decoder { return selfDecoder{ binary.NewReader(r), } }
func (codecType bytesCodecType) NewDecoder(r io.Reader) link.Decoder { return bytesDecoder{ codecType.Spliter, binary.NewReader(r), } }
func (_ selfCodecType) NewCodec(r io.Reader, w io.Writer) Codec { return selfCodec{ binary.NewReader(r), binary.NewWriter(w), } }
func (_ selfCodecType) NewStreamCodec(r *bufio.Reader, w *bufio.Writer) StreamCodec { return selfStreamCodec{ binary.NewReader(r), binary.NewWriter(w), } }
func (_ selfCodecType) NewPacketCodec() PacketCodec { codec := &selfPacketCodec{} codec.r = binary.NewReader(&codec.rbuf) codec.w = binary.NewWriter(&codec.wbuf) return codec }