{"id":16390956,"url":"https://github.com/lwch/crpc","last_synced_at":"2025-03-21T02:32:09.370Z","repository":{"id":142775111,"uuid":"613676523","full_name":"lwch/crpc","owner":"lwch","description":"golang rpc框架，支持数据加密传输","archived":false,"fork":false,"pushed_at":"2024-09-30T07:22:30.000Z","size":128,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T04:44:45.516Z","etag":null,"topics":["golang","rpc","streaming"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lwch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-14T03:29:53.000Z","updated_at":"2024-09-06T00:15:51.000Z","dependencies_parsed_at":"2023-10-04T19:31:28.218Z","dependency_job_id":"985eb5d4-5618-4d0d-8d7d-486530a57a0e","html_url":"https://github.com/lwch/crpc","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Fcrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Fcrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Fcrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Fcrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lwch","download_url":"https://codeload.github.com/lwch/crpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221811384,"owners_count":16884305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","rpc","streaming"],"created_at":"2024-10-11T04:44:42.903Z","updated_at":"2024-10-28T09:10:25.864Z","avatar_url":"https://github.com/lwch.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crpc\n\n[![crpc](https://github.com/lwch/crpc/actions/workflows/build.yml/badge.svg)](https://github.com/lwch/crpc/actions/workflows/build.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/lwch/crpc)](https://goreportcard.com/report/github.com/lwch/crpc)\n[![Go Reference](https://pkg.go.dev/badge/badge/github.com/lwch/crpc.svg)](https://pkg.go.dev/badge/github.com/lwch/crpc)\n[![license](https://img.shields.io/github/license/lwch/crpc)](https://opensource.org/licenses/MIT)\n\ngolang rpc框架，支持以下功能：\n\n1. 流式传输\n2. 数据加密\n3. 数据压缩\n4. 结构序列化，已支持数据类型：\n    - []byte\n    - http.Request, http.Response\n    - proto.Message\n\n## 分层设计\n\n在crpc框架使用以下的多层设计，每一个层次有其相应的数据结构\n\n    +------------+-------------------+--------------------+-------+\n    | data frame | encrypt(optional) | compress(optional) | codec |\n    +------------+-------------------+--------------------+-------+\n\n- `data frame`: 数据帧，最底层数据结构，直接面向于tcp协议\n- `encrypt`: 数据加密层，目前已支持aes和des加密算法\n- `compress`: 数据压缩层，目前已支持gzip和zstd压缩算法\n- `codec`: 数据序列化层，目前支持`[]byte`、`http.Request`、`http.Response`三种数据结构的序列化\n\n### 数据帧(network)\n\n数据帧为最基础数据结构，直接作用于tcp链路，其封装格式如下\n\n    +-------------+---------+----------+---------+---------+\n    | Sequence(4) | Size(2) | Crc32(4) | Flag(4) | Payload |\n    +-------------+---------+----------+---------+---------+\n\n以上内容括号中的数字表示字节数，其中`Flag`字段为枚举类型，枚举值如下\n\n    +---------+------------+----------+---------+---------+---------+-----------+---------------+\n    | Open(1) | OpenAck(1) | Close(1) | Data(1) | Ping(1) | Pong(1) | Unused(2) | Stream ID(24) |\n    +---------+------------+----------+---------+---------+---------+-----------+---------------+\n\n以上内容括号中的数字表示比特位，其中每一个比特位代表一个标志位，互相之间是互斥关系，目前仅使用了`Flag`字段第一字节的高6位，由于Stream ID字段仅有3字节，因此crpc中仅支持16777215个stream`同时`传输数据\n\n### 数据加密层(encoding/encrypt)\n\n数据加密层用于将原始数据进行加密，在数据加密前会将原始数据的crc32校验码添加到数据尾部作为解密后的校验依据，其封装格式如下：\n\n    +----------+----------+\n    + Src Data | Crc32(4) |\n    +----------+----------+\n\n- `aes`加密算法: aes加密算法使用32字节长度密钥以及16字节的iv进行CBC算法加密\n- `des`加密算法: des加密算法使用24字节长度密钥以及8字节的iv进行TripleDES算法加密\n\n当给定密钥长度不足时，底层会重复多次密钥内容以保证加密运算的进行\n\n### 数据压缩层(encoding/compress)\n\n数据压缩层用于将原始数据进行压缩，在数据压缩前会将原始数据的crc32校验码添加到数据尾部作为解压后的校验依据，其封装格式如下：\n\n    +----------+----------+\n    + Src Data | Crc32(4) |\n    +----------+----------+\n\n### 数据编码层(encoding/codec)\n\n数据编码层用于描述原始数据类型，主要作用于数据的序列化和反序列化过程，数据结构如下：\n\n    +---------+---------+\n    + Type(1) | Payload |\n    +---------+---------+\n\n其中Type字段为1字节，表示当前数据类型，定义如下：\n\n- `0`: 未知数据类型\n- `1`: raw data，可反序列化到[]byte\n- `2`: http request，可反序列化到http.Request\n- `3`: http response，可反序列化到http.Response\n- `4`: protobuf，可反序列化到proto.Message\n\n#### http请求\n\ngrpc框架底层使用`X-Crpc-Request-Id`字段进行request与response的关联，因此在使用过程中请勿使用该字段。\n\n## 示例\n\nTODO","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flwch%2Fcrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flwch%2Fcrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flwch%2Fcrpc/lists"}