Mosquitto-1.5.4源码分析,把握全局的数据结构

简介: Mosquitto-1.5.4源码分析,把握全局的数据结构

/lib/mosquitto_internal.h

struct mosquitto { //结构体struct mosquito主要用于保存一个客户端连接的所有信息,例如用户名、密码、用户ID、向该客户端发送的消息等
    mosq_sock_t sock; /*服务器程序与该客户端连接通信所用的socket描述符*/
#ifndef WITH_BROKER
  mosq_sock_t sockpairR, sockpairW;
#endif
#if defined(__GLIBC__) && defined(WITH_ADNS)
  struct gaicb *adns; /* For getaddrinfo_a */
#endif
  enum mosquitto__protocol protocol;
    char *address; /*该客户端的IP地址*/
    char *id; /*该客户端登陆mosquitto程序时所提供的ID值,该值与其他的客户端不能重复*/
  char *username;
  char *password;
    uint16_t keepalive; /*该客户端需在此时间内向mosquitto服务器程序发送一条ping/pong消息*/
  uint16_t last_mid;
  enum mosquitto_client_state state;
    time_t last_msg_in; /*last_msg_in和last_msg_out用于记录上次收发消息的时间*/
  time_t next_msg_out;
  time_t ping_t;
  struct mosquitto__packet in_packet;
  struct mosquitto__packet *current_out_packet;
  struct mosquitto__packet *out_packet;
  struct mosquitto_message *will;
    ......

/src/mosquitto_broker_internal.h


struct mosquitto__subleaf { //firecat,leaf叶子,对某一topic的所有订阅者被组织成一个订阅列表,该订阅列表是一个双向链表,链表的每个节点都保存有一个订阅者
    struct mosquitto__subleaf *prev; /*前指针*/
    struct mosquitto__subleaf *next; /*后指针*/
    struct mosquitto *context; /*表示一个订阅客户端*/
    int qos; /* Qos Level */
};
struct mosquitto__subhier { //用来保存订阅树的所有节点(包括叶子节点和中间节点),mosquitto中对订阅树采用孩子-兄弟链表法的方式进行存储
  UT_hash_handle hh;
  struct mosquitto__subhier *parent;
    struct mosquitto__subhier *children; /*第一个孩子节点*/
    struct mosquitto__subleaf *subs; /*指向订阅列表*/
  struct mosquitto_msg_store *retained;
    mosquitto__topic_element_uhpa topic; /*订阅主题*/
  uint16_t topic_len;
};
struct mosquitto_db{ //结构体struct mosquitto_db是mosquitto对所有内部数据的统一管理结构,可以认为是其内部的一个内存数据库。
                     //它保存了所有的客户端,所有客户端的订阅关系等等
  dbid_t last_db_id;
    struct mosquitto__subhier *subs; /*订阅树的总树根*/
  struct mosquitto__unpwd *unpwd;
  struct mosquitto__unpwd *psk_id;
    struct mosquitto *contexts_by_id; /*所有的客户端都在此数组中保存*/
  struct mosquitto *contexts_by_sock;
  struct mosquitto *contexts_for_free;
#ifdef WITH_BRIDGE
  struct mosquitto **bridges;
#endif
    struct clientid__index_hash *clientid_index_hash; /*用于保存一个hash表,该hash表可通过客户端的ID快速找到该客户端在数组contexts中的索引*/
  struct mosquitto_msg_store *msg_store;
  struct mosquitto_msg_store_load *msg_store_load;
#ifdef WITH_BRIDGE
  int bridge_count;
#endif
  int msg_store_count;
  unsigned long msg_store_bytes;
  char *config_file;
    struct mosquitto__config *config; /*保存所有配置信息*/
  int auth_plugin_count;
  bool verbose;
#ifdef WITH_SYS_TREE
  int subscription_count;
  int retained_count;
#endif
  int persistence_changes;
  struct mosquitto *ll_for_free;
#ifdef WITH_EPOLL
  int epollfd;
#endif
};
相关文章
|
1天前
|
存储 API
milvus insert api的数据结构源码分析
milvus insert api的数据结构源码分析
875 6
milvus insert api的数据结构源码分析
|
存储 算法 Java
《恋上数据结构第1季》哈希表介绍以及从源码分析哈希值计算
《恋上数据结构第1季》哈希表介绍以及从源码分析哈希值计算
109 0
《恋上数据结构第1季》哈希表介绍以及从源码分析哈希值计算
|
存储 NoSQL Unix
Redis 源码分析客户端数据结构(serverDb)
数据库存储在 redisDb 结构中,而服务端 redisServer 结构中保存着 redisDb 对象和个数,个数可以在配置文件中进行更新。
246 0
Redis 源码分析客户端数据结构(serverDb)
|
监控 NoSQL Redis
Redis 源码分析客户端数据结构(client)(下)
Redis 源码分析客户端数据结构(client)
404 0
Redis 源码分析客户端数据结构(client)(下)
|
NoSQL 网络协议 Redis
Redis 源码分析客户端数据结构(client)(上)
Redis 源码分析客户端数据结构(client)
233 0
|
存储 Java 索引
netty案例,netty4.1源码分析篇四《ByteBuf的数据结构在使用方式中的剖析》
在Netty中ByteBuf是一个非常重要的类,它可以以高效易用的数据结构方式来满足网络通信过程中处理数据包内字节码序列的移动。
182 0
netty案例,netty4.1源码分析篇四《ByteBuf的数据结构在使用方式中的剖析》
|
存储
Mosquitto-1.5.4源码分析,主题订阅的数据结构及SUBSCRIBE的函数跳转关系
Mosquitto-1.5.4源码分析,主题订阅的数据结构及SUBSCRIBE的函数跳转关系
298 0
Mosquitto-1.5.4源码分析,主题订阅的数据结构及SUBSCRIBE的函数跳转关系
|
C语言
Mosquitto-1.5.4源码分析,数据结构之哈希表uthash
Mosquitto-1.5.4源码分析,数据结构之哈希表uthash
200 0
|
存储 编解码 缓存
ffplay源码分析2-数据结构
ffplay是FFmpeg工程自带的简单播放器,使用FFmpeg提供的解码器和SDL库进行视频播放。
166 0
ffplay源码分析2-数据结构
|
人工智能 网络性能优化 人机交互
2. VPP源码分析(内存管理之抽象数据结构)
1.2. 抽象数据结构 1.2.1. vector CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
5097 0