示例#1
0
func NewDNSTransportUpstreamCodec(domain string) (*DNSTransportUpstreamCodec, error) {
	ret := DNSTransportUpstreamCodec{domain: domain + "."}
	var ok bool
	if ret.domain_label_count, ok = dns.IsDomainName(ret.domain); !ok {
		return nil, fmt.Errorf("Bad domain %d", domain)
	}
	name_len := 255 - len(ret.domain)
	name_len -= 9 // seq number (4 byte --base32--> 8byte) + '.'

	ret.max_len_per_name = name_len / 64 * DNS_UPSTREAM_MAX_LEN_PER_LABEL
	if tmp := name_len % 64; tmp > 9 {
		ret.max_len_per_name += (tmp - 1) / 8 * 5
	}
	ret.header_codec = bitcodec.NewBitcodec(&DNSCodecHeader{})

	return &ret, nil
}
示例#2
0
func NewDNSTransportDownstreamCodec() *DNSTransportDownstreamCodec {
	codec := DNSTransportDownstreamCodec{}
	codec.header_codec = bitcodec.NewBitcodec(&DNSCodecHeader{})
	return &codec
}