Code Monkey home page Code Monkey logo

dns-relay-demo's Introduction

DNS-Relay —— DNS中继器

1. 框架

流程图

2. 编码规范

  • 变量名: yourFather
  • 函数名: YourFather
  • 文件名: your_father
  • 不要在.h文件里面声明任何变量
  • 结构体声明放在.h
  • 所有的全局变量都用static修饰,需要访问的话提供接口
  • 不需要被外部调用的函数不用在.h中声明,只需要在.cpp中用static修饰定义
  • 所有的外部函数(被其他模块的调用的函数)必须加extern,(虽然这个extern没有什么意义);
  • 所有表示一个字节的内存区必须使用unsigned char
  • include全部放在.h文件吧,防止重复定义
  • 注释统一使用 /* ... */ 不要用//
  • else 不换行, 记得在格式化设置里面调好。

3. 接口说明

4. 结构体设计

[1] clientRecord

typedef struct {
	SOCKADDR addr;
	DNSID originId;
	unsigned char r;
}CRecord;

[2] clientTable

typedef struct {
	CRecord base[MAX_QUERIES];
	int front;
	int rear;
}CQueue;
  • 由多个clientRecord组成的队列,循环数组。
  • 服务器最多支持MAX_QUERY个请求同时等待。队列满了之后丢弃新包。
  • 每次收到一个来自客户端的query报文时。
    • 将客户端地址和报文ID入队。
    • 如果入队成功,调用获取队尾元素序号,作为转发DNS的ID发送给服务器。
  • 每次收到一个response时。
    • 在队列中查找对应ID的query是否未回复。
    • 如果未回复,则回复并将r置为1。
    • 并且把这个DNS发回给客户端。
  • 每次检查计时器时。
    • 从队头开始检查。
    • 如果已经回复,则将其pop出来。
    • 如果超时,则将其pop出来重新加入队列并发送。
    • 如果没有超时并且r=0,则停止检查。

[3] DNSHeader(待完善)

typedef struct dnsheader{
	unsigned short ID;		
	unsigned short FLAGS;	/*2字节的各种flag*/
	unsigned short QDCOUNT;	
	unsigned short ANCOUNT;
	unsigned short NSCOUNT;
	unsigned short ARCOUNT;
}DNSHeader;
  • FLAGS包含很多字段。

[4]Cache

  • 对外提供插入方法, 只有查询到网络报文的时候才需要调用
  • 查找方法和自动插入会在查询数据库的时候先触发, 模拟cpu cache

5. 待解决问题

  • 如何处理0.0.0.0的记录?
    • 返回找不到.
  • 字节序:超过一个字节长度的字段,字节之间的顺序相反。

dns-relay-demo's People

Contributors

magic-knight avatar tkoniy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.