From 1be41c7979f8fc1eaeb87d126601c29a2a4fbd45 Mon Sep 17 00:00:00 2001 From: FrankieLiu04 Date: Tue, 6 Jan 2026 23:00:37 +0800 Subject: [PATCH 1/4] chore: add collaboration infrastructure - Add MIT LICENSE - Add CONTRIBUTING.md with branch strategy and commit conventions - Add CODE_OF_CONDUCT.md - Add GitHub Issue templates (bug report, feature request) - Add Pull Request template - Add .editorconfig for consistent coding style - Add .clang-format for C++ code formatting --- .clang-format | 75 +++++++++++++ .editorconfig | 52 +++++++++ .github/ISSUE_TEMPLATE/bug_report.md | 37 +++++++ .github/ISSUE_TEMPLATE/feature_request.md | 29 +++++ .github/PULL_REQUEST_TEMPLATE.md | 33 ++++++ CODE_OF_CONDUCT.md | 44 ++++++++ CONTRIBUTING.md | 122 ++++++++++++++++++++++ LICENSE | 21 ++++ 8 files changed, 413 insertions(+) create mode 100644 .clang-format create mode 100644 .editorconfig create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..8bbaf00 --- /dev/null +++ b/.clang-format @@ -0,0 +1,75 @@ +# Clang-Format 配置文件 +# 基于 Google C++ 风格,适度调整 + +Language: Cpp +BasedOnStyle: Google + +# 缩进 +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +AccessModifierOffset: -4 + +# 行宽 +ColumnLimit: 100 + +# 大括号 +BreakBeforeBraces: Attach +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortBlocksOnASingleLine: Empty + +# 指针和引用对齐 +PointerAlignment: Left +ReferenceAlignment: Left + +# 包含文件排序 +SortIncludes: CaseSensitive +IncludeBlocks: Regroup +IncludeCategories: + # 1. 本项目头文件 + - Regex: '^"(client|server|common|protocol)/' + Priority: 1 + # 2. 第三方库 + - Regex: '^<.*\.h>' + Priority: 2 + # 3. C++ 标准库 + - Regex: '^<.*>' + Priority: 3 + +# 命名空间 +NamespaceIndentation: None +CompactNamespaces: false +FixNamespaceComments: true + +# 对齐 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignOperands: true +AlignTrailingComments: true + +# 换行 +AllowAllParametersOfDeclarationOnNextLine: true +BinPackArguments: true +BinPackParameters: true +BreakConstructorInitializers: BeforeColon +ConstructorInitializerAllOnOneLineOrOnePerLine: true + +# 空格 +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpacesInAngles: false +SpacesInParentheses: false +SpacesInSquareBrackets: false + +# C++11 特性 +Standard: c++17 +Cpp11BracedListStyle: true + +# 注释 +ReflowComments: true +SpacesBeforeTrailingComments: 2 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5de53b3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,52 @@ +# EditorConfig 帮助开发者在不同编辑器间保持一致的编码风格 +# https://editorconfig.org + +root = true + +# 默认设置(适用于所有文件) +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 + +# C/C++ 文件 +[*.{c,cc,cpp,h,hpp}] +indent_size = 4 + +# CMake 文件 +[CMakeLists.txt] +indent_size = 4 + +[*.cmake] +indent_size = 4 + +# Markdown 文件(保留尾部空格用于换行) +[*.md] +trim_trailing_whitespace = false + +# YAML 文件 +[*.{yml,yaml}] +indent_size = 2 + +# JSON 文件 +[*.json] +indent_size = 2 + +# Shell 脚本 +[*.sh] +indent_size = 2 + +# Batch 脚本 +[*.bat] +end_of_line = crlf + +# Makefile(必须使用 tab) +[Makefile] +indent_style = tab + +# Docker 文件 +[Dockerfile*] +indent_size = 4 diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..9412c8d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,37 @@ +--- +name: Bug 报告 +about: 报告一个 bug 帮助我们改进 +title: '[BUG] ' +labels: bug +assignees: '' +--- + +## 🐛 Bug 描述 +简要描述这个 bug 是什么。 + +## 📝 复现步骤 +1. 执行 '...' +2. 运行命令 '...' +3. 查看错误 + +## ✅ 期望行为 +描述你期望发生什么。 + +## ❌ 实际行为 +描述实际发生了什么。 + +## 🖥️ 环境信息 +- 操作系统: [例如 Ubuntu 22.04 / Windows 11] +- 编译器: [例如 GCC 11.4 / MSVC 19.36] +- CMake 版本: [例如 3.22] + +## 📋 日志输出 +``` +粘贴相关日志输出 +``` + +## 📷 截图 +如有必要,添加截图。 + +## 💡 其他信息 +添加任何其他有关该问题的上下文。 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..b46c34c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,29 @@ +--- +name: 功能请求 +about: 提出新功能或改进建议 +title: '[FEATURE] ' +labels: enhancement +assignees: '' +--- + +## 🚀 功能描述 +简要描述你想要的功能。 + +## 💡 动机 +为什么需要这个功能?它解决什么问题? + +## 📋 详细设计(可选) +如果你有实现思路,请描述: + +### 方案 +描述你提议的解决方案。 + +### 替代方案 +你考虑过的其他方案。 + +## ✅ 验收标准 +- [ ] 标准 1 +- [ ] 标准 2 + +## 📚 参考资料 +相关链接、文档或示例。 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..1dfd622 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,33 @@ +## 📋 PR 描述 +简要描述这个 PR 做了什么。 + +## 🔗 关联 Issue +Closes #(issue编号) + +## 🔄 变更类型 +请勾选适用的选项: + +- [ ] 🐛 Bug 修复 (fix) +- [ ] ✨ 新功能 (feat) +- [ ] 📝 文档更新 (docs) +- [ ] 🎨 代码格式/风格 (style) +- [ ] ♻️ 代码重构 (refactor) +- [ ] ✅ 测试相关 (test) +- [ ] 🔧 构建/配置 (chore) + +## 📝 变更详情 +- 变更点 1 +- 变更点 2 + +## ✅ 自检清单 +- [ ] 代码可以正常编译 +- [ ] 所有测试通过 +- [ ] 已添加必要的测试 +- [ ] 已更新相关文档 +- [ ] Commit 消息符合规范 + +## 🧪 测试说明 +描述如何测试这些变更。 + +## 📷 截图(如适用) +UI 变更的截图。 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..22252fe --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,44 @@ +# 贡献者行为准则 | Contributor Covenant Code of Conduct + +## 我们的承诺 + +为了营造一个开放和友好的环境,我们作为贡献者和维护者承诺:无论年龄、体型、残疾、种族、性别特征、性别认同和表达、经验水平、教育程度、社会经济地位、国籍、外貌、种族、宗教或性取向如何,参与我们项目和社区的每个人都不会受到骚扰。 + +## 我们的标准 + +有助于创造积极环境的行为包括: + +* 使用友好和包容的语言 +* 尊重不同的观点和经验 +* 优雅地接受建设性批评 +* 专注于对社区最有利的事情 +* 对其他社区成员表示同理心 + +不可接受的参与者行为包括: + +* 使用性暗示的语言或图像,以及不受欢迎的性关注或性挑逗 +* 恶意挑衅、侮辱/贬损性评论以及个人或政治攻击 +* 公开或私下骚扰 +* 未经明确许可,发布他人的私人信息,如住址或电子邮件地址 +* 其他可以合理地被认为在专业环境中不适当的行为 + +## 我们的责任 + +项目维护者有责任为可接受的行为标准做出诠释,并对任何不可接受的行为采取恰当且公平的纠正措施。 + +项目维护者有权且有责任删除、编辑或拒绝与本行为准则不符的评论、提交、代码、wiki 编辑、Issue 和其他贡献,并可以暂时或永久性地封禁任何他们认为行为不适当、威胁、冒犯或有害的贡献者。 + +## 适用范围 + +本行为准则适用于所有项目空间,当个人在公共空间代表项目或其社区时也适用。代表项目或社区的例子包括使用官方项目电子邮件地址、通过官方社交媒体账户发布消息,或在线上或线下活动中担任指定代表。 + +## 执行 + +如遇到辱骂、骚扰或其他不可接受的行为,可以通过创建 Issue 联系项目团队进行举报。所有投诉都将被审查和调查,并将做出被认为必要且适合具体情况的回应。项目团队有义务对事件举报者保密。 + +## 归属 + +本行为准则改编自 [Contributor Covenant][homepage] 2.0 版, +可在 https://www.contributor-covenant.org/version/2/0/code_of_conduct.html 获取。 + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e41b0b0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,122 @@ +# 贡献指南 | Contributing Guide + +感谢你对本项目的兴趣!以下是参与贡献的指南。 + +## 🌿 分支策略 + +我们采用简化的 Git Flow 模型: + +| 分支 | 用途 | 保护级别 | +|------|------|----------| +| `main` | 稳定发布版本 | 受保护,需要 PR | +| `develop` | 开发集成分支 | 需要 PR | +| `feature/*` | 新功能开发 | 个人分支 | +| `bugfix/*` | Bug 修复 | 个人分支 | + +### 分支命名规范 + +``` +feature/添加文件压缩功能 +feature/add-compression +bugfix/修复连接超时问题 +bugfix/fix-connection-timeout +docs/更新README +``` + +## 📝 如何贡献 + +### 1. Fork & Clone + +```bash +# Fork 本仓库后 +git clone https://github.com/你的用户名/Computer_Network_lab.git +cd Computer_Network_lab +git remote add upstream https://github.com/FrankieLiu04/Computer_Network_lab.git +``` + +### 2. 创建功能分支 + +```bash +git checkout develop +git pull upstream develop +git checkout -b feature/你的功能名称 +``` + +### 3. 开发 & 提交 + +```bash +# 进行开发... +git add . +git commit -m "feat: 添加新功能描述" +``` + +#### Commit 消息规范 + +我们使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范: + +| 类型 | 说明 | +|------|------| +| `feat` | 新功能 | +| `fix` | Bug 修复 | +| `docs` | 文档更新 | +| `style` | 代码格式(不影响逻辑) | +| `refactor` | 重构 | +| `test` | 测试相关 | +| `chore` | 构建/工具变动 | + +示例: +``` +feat: 添加文件断点续传功能 +fix: 修复大文件传输时的内存溢出问题 +docs: 更新 Docker 部署文档 +``` + +### 4. 推送 & 创建 PR + +```bash +git push origin feature/你的功能名称 +``` + +然后在 GitHub 上创建 Pull Request,目标分支选择 `develop`。 + +## ✅ PR 检查清单 + +提交 PR 前请确认: + +- [ ] 代码能够正常编译 +- [ ] 所有测试通过 (`ctest` 或 CI) +- [ ] 遵循代码风格规范 +- [ ] 更新了相关文档(如需要) +- [ ] Commit 消息符合规范 + +## 🏗️ 本地开发环境 + +### 依赖 + +- CMake 3.16+ +- C++17 兼容编译器 +- Docker(可选,用于容器化测试) + +### 构建 + +```bash +cd reliable-remote-backup-system +cmake -B build -DCMAKE_BUILD_TYPE=Debug +cmake --build build +``` + +### 测试 + +```bash +cd build +ctest --output-on-failure +``` + +## 💬 寻求帮助 + +- 有问题?创建 [Issue](https://github.com/FrankieLiu04/Computer_Network_lab/issues) +- 想讨论?使用 Issue 的 `question` 标签 + +## 📜 行为准则 + +请阅读我们的 [行为准则](CODE_OF_CONDUCT.md),确保友好、包容的协作环境。 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c6f892c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 FrankieLiu04 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 42343b4ce7e0632d5942b309ce50b3d67bf49533 Mon Sep 17 00:00:00 2001 From: FrankieLiu04 Date: Tue, 6 Jan 2026 23:07:06 +0800 Subject: [PATCH 2/4] refactor: convert docs to English with Chinese translations - Convert CONTRIBUTING.md and CODE_OF_CONDUCT.md to English - Add Chinese versions as CONTRIBUTING.zh-CN.md and CODE_OF_CONDUCT.zh-CN.md - Add language switcher badges for bilingual support --- CODE_OF_CONDUCT.md | 83 ++++++++++++++++++-------- CODE_OF_CONDUCT.zh-CN.md | 46 +++++++++++++++ CONTRIBUTING.md | 118 +++++++++++++++++++------------------ CONTRIBUTING.zh-CN.md | 124 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 287 insertions(+), 84 deletions(-) create mode 100644 CODE_OF_CONDUCT.zh-CN.md create mode 100644 CONTRIBUTING.zh-CN.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 22252fe..2aaa013 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,44 +1,75 @@ -# 贡献者行为准则 | Contributor Covenant Code of Conduct +# Contributor Covenant Code of Conduct -## 我们的承诺 +[![中文](https://img.shields.io/badge/lang-中文-red.svg)](CODE_OF_CONDUCT.zh-CN.md) -为了营造一个开放和友好的环境,我们作为贡献者和维护者承诺:无论年龄、体型、残疾、种族、性别特征、性别认同和表达、经验水平、教育程度、社会经济地位、国籍、外貌、种族、宗教或性取向如何,参与我们项目和社区的每个人都不会受到骚扰。 +## Our Pledge -## 我们的标准 +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. -有助于创造积极环境的行为包括: +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. -* 使用友好和包容的语言 -* 尊重不同的观点和经验 -* 优雅地接受建设性批评 -* 专注于对社区最有利的事情 -* 对其他社区成员表示同理心 +## Our Standards -不可接受的参与者行为包括: +Examples of behavior that contributes to a positive environment for our +community include: -* 使用性暗示的语言或图像,以及不受欢迎的性关注或性挑逗 -* 恶意挑衅、侮辱/贬损性评论以及个人或政治攻击 -* 公开或私下骚扰 -* 未经明确许可,发布他人的私人信息,如住址或电子邮件地址 -* 其他可以合理地被认为在专业环境中不适当的行为 +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community -## 我们的责任 +Examples of unacceptable behavior include: -项目维护者有责任为可接受的行为标准做出诠释,并对任何不可接受的行为采取恰当且公平的纠正措施。 +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting -项目维护者有权且有责任删除、编辑或拒绝与本行为准则不符的评论、提交、代码、wiki 编辑、Issue 和其他贡献,并可以暂时或永久性地封禁任何他们认为行为不适当、威胁、冒犯或有害的贡献者。 +## Enforcement Responsibilities -## 适用范围 +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. -本行为准则适用于所有项目空间,当个人在公共空间代表项目或其社区时也适用。代表项目或社区的例子包括使用官方项目电子邮件地址、通过官方社交媒体账户发布消息,或在线上或线下活动中担任指定代表。 +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. -## 执行 +## Scope -如遇到辱骂、骚扰或其他不可接受的行为,可以通过创建 Issue 联系项目团队进行举报。所有投诉都将被审查和调查,并将做出被认为必要且适合具体情况的回应。项目团队有义务对事件举报者保密。 +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. -## 归属 +## Enforcement -本行为准则改编自 [Contributor Covenant][homepage] 2.0 版, -可在 https://www.contributor-covenant.org/version/2/0/code_of_conduct.html 获取。 +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by creating an issue in this repository. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. [homepage]: https://www.contributor-covenant.org diff --git a/CODE_OF_CONDUCT.zh-CN.md b/CODE_OF_CONDUCT.zh-CN.md new file mode 100644 index 0000000..0b6860b --- /dev/null +++ b/CODE_OF_CONDUCT.zh-CN.md @@ -0,0 +1,46 @@ +# 贡献者行为准则 + +[![English](https://img.shields.io/badge/lang-English-blue.svg)](CODE_OF_CONDUCT.md) + +## 我们的承诺 + +为了营造一个开放和友好的环境,我们作为贡献者和维护者承诺:无论年龄、体型、残疾、种族、性别特征、性别认同和表达、经验水平、教育程度、社会经济地位、国籍、外貌、种族、宗教或性取向如何,参与我们项目和社区的每个人都不会受到骚扰。 + +## 我们的标准 + +有助于创造积极环境的行为包括: + +* 使用友好和包容的语言 +* 尊重不同的观点和经验 +* 优雅地接受建设性批评 +* 专注于对社区最有利的事情 +* 对其他社区成员表示同理心 + +不可接受的参与者行为包括: + +* 使用性暗示的语言或图像,以及不受欢迎的性关注或性挑逗 +* 恶意挑衅、侮辱/贬损性评论以及个人或政治攻击 +* 公开或私下骚扰 +* 未经明确许可,发布他人的私人信息,如住址或电子邮件地址 +* 其他可以合理地被认为在专业环境中不适当的行为 + +## 我们的责任 + +项目维护者有责任为可接受的行为标准做出诠释,并对任何不可接受的行为采取恰当且公平的纠正措施。 + +项目维护者有权且有责任删除、编辑或拒绝与本行为准则不符的评论、提交、代码、wiki 编辑、Issue 和其他贡献,并可以暂时或永久性地封禁任何他们认为行为不适当、威胁、冒犯或有害的贡献者。 + +## 适用范围 + +本行为准则适用于所有项目空间,当个人在公共空间代表项目或其社区时也适用。代表项目或社区的例子包括使用官方项目电子邮件地址、通过官方社交媒体账户发布消息,或在线上或线下活动中担任指定代表。 + +## 执行 + +如遇到辱骂、骚扰或其他不可接受的行为,可以通过创建 Issue 联系项目团队进行举报。所有投诉都将被审查和调查,并将做出被认为必要且适合具体情况的回应。项目团队有义务对事件举报者保密。 + +## 归属 + +本行为准则改编自 [Contributor Covenant][homepage] 2.0 版, +可在 https://www.contributor-covenant.org/version/2/0/code_of_conduct.html 获取。 + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e41b0b0..b3055a2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,103 +1,105 @@ -# 贡献指南 | Contributing Guide +# Contributing Guide -感谢你对本项目的兴趣!以下是参与贡献的指南。 +[![中文](https://img.shields.io/badge/lang-中文-red.svg)](CONTRIBUTING.zh-CN.md) -## 🌿 分支策略 +Thank you for your interest in contributing to this project! Here's how you can help. -我们采用简化的 Git Flow 模型: +## 🌿 Branching Strategy -| 分支 | 用途 | 保护级别 | -|------|------|----------| -| `main` | 稳定发布版本 | 受保护,需要 PR | -| `develop` | 开发集成分支 | 需要 PR | -| `feature/*` | 新功能开发 | 个人分支 | -| `bugfix/*` | Bug 修复 | 个人分支 | +We use a simplified Git Flow model: -### 分支命名规范 +| Branch | Purpose | Protection | +|--------|---------|------------| +| `main` | Stable releases | Protected, PR required | +| `develop` | Development integration | PR required | +| `feature/*` | New features | Personal branches | +| `bugfix/*` | Bug fixes | Personal branches | + +### Branch Naming Convention ``` -feature/添加文件压缩功能 feature/add-compression -bugfix/修复连接超时问题 +feature/file-encryption bugfix/fix-connection-timeout -docs/更新README +bugfix/memory-leak-fix +docs/update-readme ``` -## 📝 如何贡献 +## 📝 How to Contribute ### 1. Fork & Clone ```bash -# Fork 本仓库后 -git clone https://github.com/你的用户名/Computer_Network_lab.git +# After forking the repository +git clone https://github.com/YOUR_USERNAME/Computer_Network_lab.git cd Computer_Network_lab git remote add upstream https://github.com/FrankieLiu04/Computer_Network_lab.git ``` -### 2. 创建功能分支 +### 2. Create a Feature Branch ```bash git checkout develop git pull upstream develop -git checkout -b feature/你的功能名称 +git checkout -b feature/your-feature-name ``` -### 3. 开发 & 提交 +### 3. Develop & Commit ```bash -# 进行开发... +# Make your changes... git add . -git commit -m "feat: 添加新功能描述" +git commit -m "feat: add your feature description" ``` -#### Commit 消息规范 +#### Commit Message Convention -我们使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范: +We follow [Conventional Commits](https://www.conventionalcommits.org/) specification: -| 类型 | 说明 | -|------|------| -| `feat` | 新功能 | -| `fix` | Bug 修复 | -| `docs` | 文档更新 | -| `style` | 代码格式(不影响逻辑) | -| `refactor` | 重构 | -| `test` | 测试相关 | -| `chore` | 构建/工具变动 | +| Type | Description | +|------|-------------| +| `feat` | New feature | +| `fix` | Bug fix | +| `docs` | Documentation update | +| `style` | Code style (no logic change) | +| `refactor` | Code refactoring | +| `test` | Test related | +| `chore` | Build/tooling changes | -示例: +Examples: ``` -feat: 添加文件断点续传功能 -fix: 修复大文件传输时的内存溢出问题 -docs: 更新 Docker 部署文档 +feat: add resumable file upload +fix: resolve memory overflow for large files +docs: update Docker deployment guide ``` -### 4. 推送 & 创建 PR +### 4. Push & Create PR ```bash -git push origin feature/你的功能名称 +git push origin feature/your-feature-name ``` -然后在 GitHub 上创建 Pull Request,目标分支选择 `develop`。 +Then create a Pull Request on GitHub targeting the `develop` branch. -## ✅ PR 检查清单 +## ✅ PR Checklist -提交 PR 前请确认: +Before submitting your PR, please verify: -- [ ] 代码能够正常编译 -- [ ] 所有测试通过 (`ctest` 或 CI) -- [ ] 遵循代码风格规范 -- [ ] 更新了相关文档(如需要) -- [ ] Commit 消息符合规范 +- [ ] Code compiles successfully +- [ ] All tests pass (`ctest` or CI) +- [ ] Code follows style guidelines +- [ ] Documentation updated (if needed) +- [ ] Commit messages follow conventions -## 🏗️ 本地开发环境 +## 🏗️ Development Environment -### 依赖 +### Requirements - CMake 3.16+ -- C++17 兼容编译器 -- Docker(可选,用于容器化测试) +- C++17 compatible compiler +- Docker (optional, for containerized testing) -### 构建 +### Build ```bash cd reliable-remote-backup-system @@ -105,18 +107,18 @@ cmake -B build -DCMAKE_BUILD_TYPE=Debug cmake --build build ``` -### 测试 +### Test ```bash cd build ctest --output-on-failure ``` -## 💬 寻求帮助 +## 💬 Getting Help -- 有问题?创建 [Issue](https://github.com/FrankieLiu04/Computer_Network_lab/issues) -- 想讨论?使用 Issue 的 `question` 标签 +- Questions? Create an [Issue](https://github.com/FrankieLiu04/Computer_Network_lab/issues) +- Want to discuss? Use the `question` label -## 📜 行为准则 +## 📜 Code of Conduct -请阅读我们的 [行为准则](CODE_OF_CONDUCT.md),确保友好、包容的协作环境。 +Please read our [Code of Conduct](CODE_OF_CONDUCT.md) to maintain a friendly and inclusive environment. diff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.md new file mode 100644 index 0000000..7ea10af --- /dev/null +++ b/CONTRIBUTING.zh-CN.md @@ -0,0 +1,124 @@ +# 贡献指南 + +[![English](https://img.shields.io/badge/lang-English-blue.svg)](CONTRIBUTING.md) + +感谢你对本项目的兴趣!以下是参与贡献的指南。 + +## 🌿 分支策略 + +我们采用简化的 Git Flow 模型: + +| 分支 | 用途 | 保护级别 | +|------|------|----------| +| `main` | 稳定发布版本 | 受保护,需要 PR | +| `develop` | 开发集成分支 | 需要 PR | +| `feature/*` | 新功能开发 | 个人分支 | +| `bugfix/*` | Bug 修复 | 个人分支 | + +### 分支命名规范 + +``` +feature/add-compression +feature/file-encryption +bugfix/fix-connection-timeout +bugfix/memory-leak-fix +docs/update-readme +``` + +## 📝 如何贡献 + +### 1. Fork & Clone + +```bash +# Fork 本仓库后 +git clone https://github.com/你的用户名/Computer_Network_lab.git +cd Computer_Network_lab +git remote add upstream https://github.com/FrankieLiu04/Computer_Network_lab.git +``` + +### 2. 创建功能分支 + +```bash +git checkout develop +git pull upstream develop +git checkout -b feature/你的功能名称 +``` + +### 3. 开发 & 提交 + +```bash +# 进行开发... +git add . +git commit -m "feat: 添加新功能描述" +``` + +#### Commit 消息规范 + +我们使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范: + +| 类型 | 说明 | +|------|------| +| `feat` | 新功能 | +| `fix` | Bug 修复 | +| `docs` | 文档更新 | +| `style` | 代码格式(不影响逻辑) | +| `refactor` | 重构 | +| `test` | 测试相关 | +| `chore` | 构建/工具变动 | + +示例: +``` +feat: 添加文件断点续传功能 +fix: 修复大文件传输时的内存溢出问题 +docs: 更新 Docker 部署文档 +``` + +### 4. 推送 & 创建 PR + +```bash +git push origin feature/你的功能名称 +``` + +然后在 GitHub 上创建 Pull Request,目标分支选择 `develop`。 + +## ✅ PR 检查清单 + +提交 PR 前请确认: + +- [ ] 代码能够正常编译 +- [ ] 所有测试通过 (`ctest` 或 CI) +- [ ] 遵循代码风格规范 +- [ ] 更新了相关文档(如需要) +- [ ] Commit 消息符合规范 + +## 🏗️ 本地开发环境 + +### 依赖 + +- CMake 3.16+ +- C++17 兼容编译器 +- Docker(可选,用于容器化测试) + +### 构建 + +```bash +cd reliable-remote-backup-system +cmake -B build -DCMAKE_BUILD_TYPE=Debug +cmake --build build +``` + +### 测试 + +```bash +cd build +ctest --output-on-failure +``` + +## 💬 寻求帮助 + +- 有问题?创建 [Issue](https://github.com/FrankieLiu04/Computer_Network_lab/issues) +- 想讨论?使用 Issue 的 `question` 标签 + +## 📜 行为准则 + +请阅读我们的 [行为准则](CODE_OF_CONDUCT.zh-CN.md),确保友好、包容的协作环境。 From b5f3c6f06c4afb1d35eac3b847fcfee01825b994 Mon Sep 17 00:00:00 2001 From: FrankieLiu04 Date: Tue, 6 Jan 2026 23:07:22 +0800 Subject: [PATCH 3/4] docs: add language switcher to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dedef4a..92b573d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Computer Network Lab — Reliable Remote Backup System +[![中文](https://img.shields.io/badge/lang-中文-red.svg)](README.zh-CN.md) [![CI](https://github.com/FrankieLiu04/Computer_Network_lab/actions/workflows/ci.yml/badge.svg)](https://github.com/FrankieLiu04/Computer_Network_lab/actions/workflows/ci.yml) [![C++17](https://img.shields.io/badge/C%2B%2B-17-blue.svg)](https://isocpp.org/) [![Docker](https://img.shields.io/badge/Docker-Ready-2496ED?logo=docker&logoColor=white)](https://www.docker.com/) From f0ddf1a8b8afd3082ec1c3ebd4aea182c5d4c68c Mon Sep 17 00:00:00 2001 From: FrankieLiu04 Date: Tue, 6 Jan 2026 23:11:16 +0800 Subject: [PATCH 4/4] docs: convert all Chinese comments to English - Update PR template to English - Translate .editorconfig comments - Translate .clang-format comments - Maintain consistency with English-first documentation policy --- .clang-format | 32 ++++++++--------- .editorconfig | 22 ++++++------ .github/PULL_REQUEST_TEMPLATE.md | 52 +++++++++++++-------------- .gitignore | 10 +++--- original-labs/stable.c | 62 ++++++++++++++++---------------- 5 files changed, 89 insertions(+), 89 deletions(-) diff --git a/.clang-format b/.clang-format index 8bbaf00..05e8913 100644 --- a/.clang-format +++ b/.clang-format @@ -1,63 +1,63 @@ -# Clang-Format 配置文件 -# 基于 Google C++ 风格,适度调整 +# Clang-Format configuration file +# Based on Google C++ style with moderate adjustments Language: Cpp BasedOnStyle: Google -# 缩进 +# Indentation IndentWidth: 4 TabWidth: 4 UseTab: Never AccessModifierOffset: -4 -# 行宽 +# Line width ColumnLimit: 100 -# 大括号 +# Braces BreakBeforeBraces: Attach AllowShortIfStatementsOnASingleLine: Never AllowShortLoopsOnASingleLine: false AllowShortFunctionsOnASingleLine: Empty AllowShortBlocksOnASingleLine: Empty -# 指针和引用对齐 +# Pointer and reference alignment PointerAlignment: Left ReferenceAlignment: Left -# 包含文件排序 +# Include file sorting SortIncludes: CaseSensitive IncludeBlocks: Regroup IncludeCategories: - # 1. 本项目头文件 + # 1. Project headers - Regex: '^"(client|server|common|protocol)/' Priority: 1 - # 2. 第三方库 + # 2. Third-party libraries - Regex: '^<.*\.h>' Priority: 2 - # 3. C++ 标准库 + # 3. C++ standard library - Regex: '^<.*>' Priority: 3 -# 命名空间 +# Namespace NamespaceIndentation: None CompactNamespaces: false FixNamespaceComments: true -# 对齐 +# Alignment AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false AlignOperands: true AlignTrailingComments: true -# 换行 +# Line breaking AllowAllParametersOfDeclarationOnNextLine: true BinPackArguments: true BinPackParameters: true BreakConstructorInitializers: BeforeColon ConstructorInitializerAllOnOneLineOrOnePerLine: true -# 空格 +# Spacing SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true @@ -66,10 +66,10 @@ SpacesInAngles: false SpacesInParentheses: false SpacesInSquareBrackets: false -# C++11 特性 +# C++11 features Standard: c++17 Cpp11BracedListStyle: true -# 注释 +# Comments ReflowComments: true SpacesBeforeTrailingComments: 2 diff --git a/.editorconfig b/.editorconfig index 5de53b3..baeab80 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,9 +1,9 @@ -# EditorConfig 帮助开发者在不同编辑器间保持一致的编码风格 +# EditorConfig helps maintain consistent coding styles across different editors # https://editorconfig.org root = true -# 默认设置(适用于所有文件) +# Default settings (applies to all files) [*] charset = utf-8 end_of_line = lf @@ -12,41 +12,41 @@ trim_trailing_whitespace = true indent_style = space indent_size = 4 -# C/C++ 文件 +# C/C++ files [*.{c,cc,cpp,h,hpp}] indent_size = 4 -# CMake 文件 +# CMake files [CMakeLists.txt] indent_size = 4 [*.cmake] indent_size = 4 -# Markdown 文件(保留尾部空格用于换行) +# Markdown files (preserve trailing spaces for line breaks) [*.md] trim_trailing_whitespace = false -# YAML 文件 +# YAML files [*.{yml,yaml}] indent_size = 2 -# JSON 文件 +# JSON files [*.json] indent_size = 2 -# Shell 脚本 +# Shell scripts [*.sh] indent_size = 2 -# Batch 脚本 +# Batch scripts [*.bat] end_of_line = crlf -# Makefile(必须使用 tab) +# Makefile (must use tabs) [Makefile] indent_style = tab -# Docker 文件 +# Docker files [Dockerfile*] indent_size = 4 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 1dfd622..c0b089c 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,33 +1,33 @@ -## 📋 PR 描述 -简要描述这个 PR 做了什么。 +## 📋 PR Description +Briefly describe what this PR does. -## 🔗 关联 Issue -Closes #(issue编号) +## 🔗 Related Issue +Closes #(issue number) -## 🔄 变更类型 -请勾选适用的选项: +## 🔄 Change Type +Please check the applicable options: -- [ ] 🐛 Bug 修复 (fix) -- [ ] ✨ 新功能 (feat) -- [ ] 📝 文档更新 (docs) -- [ ] 🎨 代码格式/风格 (style) -- [ ] ♻️ 代码重构 (refactor) -- [ ] ✅ 测试相关 (test) -- [ ] 🔧 构建/配置 (chore) +- [ ] 🐛 Bug fix (fix) +- [ ] ✨ New feature (feat) +- [ ] 📝 Documentation update (docs) +- [ ] 🎨 Code format/style (style) +- [ ] ♻️ Code refactoring (refactor) +- [ ] ✅ Test related (test) +- [ ] 🔧 Build/configuration (chore) -## 📝 变更详情 -- 变更点 1 -- 变更点 2 +## 📝 Change Details +- Change 1 +- Change 2 -## ✅ 自检清单 -- [ ] 代码可以正常编译 -- [ ] 所有测试通过 -- [ ] 已添加必要的测试 -- [ ] 已更新相关文档 -- [ ] Commit 消息符合规范 +## ✅ Self-Check List +- [ ] Code compiles successfully +- [ ] All tests pass +- [ ] Necessary tests added +- [ ] Related documentation updated +- [ ] Commit messages follow conventions -## 🧪 测试说明 -描述如何测试这些变更。 +## 🧪 Testing Instructions +Describe how to test these changes. -## 📷 截图(如适用) -UI 变更的截图。 +## 📷 Screenshots (if applicable) +Screenshots of UI changes. diff --git a/.gitignore b/.gitignore index 670a86b..2186dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ -# IDE 个人化配置 +# IDE personal configurations .vscode/ *.code-workspace -# OS 文件 +# OS files .DS_Store Thumbs.db desktop.ini @@ -10,15 +10,15 @@ desktop.ini *.swo *~ -# 构建产物(如果根目录构建) +# Build artifacts (if built in root directory) build/ out/ bin/ dist/ -# 日志 +# Logs *.log -# 临时文件 +# Temporary files *.tmp *.temp diff --git a/original-labs/stable.c b/original-labs/stable.c index 80b11eb..90a12a1 100644 --- a/original-labs/stable.c +++ b/original-labs/stable.c @@ -114,7 +114,7 @@ void ComputeChecksum(struct pkt *packet) unsigned int sum = 0; sum += packet->seqnum; sum += packet->acknum; - + for(int i=0; i<20; i++) { sum += (unsigned char)packet->payload[i]; if(sum & 0xFFFF0000) { @@ -129,7 +129,7 @@ int CheckCorrupted(struct pkt packet) unsigned int sum = 0; sum += packet.seqnum; sum += packet.acknum; - + for(int i=0; i<20; i++) { sum += (unsigned char)packet.payload[i]; if(sum & 0xFFFF0000) { @@ -145,10 +145,10 @@ int CheckCorrupted(struct pkt packet) void A_output(struct msg_ message) { struct timer *pkt_timer; - + /* Create pkt before window is full */ if (nextseqnum < base + WINDOWSIZE) { - /* 创建新数据包 */ + /* Create new data packet */ struct pkt packet; packet.seqnum = nextseqnum; packet.acknum = NOTUSED; @@ -223,7 +223,7 @@ void A_input(struct pkt packet) return; // if no matching ACK found, just return } - + while (pktnum > 0 && winbuf[winfront].acknum == 1 && winbuf[winfront].seqnum == base) { base++; winfront = (winfront + 1) % WINDOWSIZE; @@ -231,7 +231,7 @@ void A_input(struct pkt packet) ack_adv_num++; } - + while (msg_num > 0 && nextseqnum < base + WINDOWSIZE) { struct msg_ message = buffer[buffront]; buffront = (buffront + 1) % MAXBUFSIZE; @@ -243,11 +243,11 @@ void A_input(struct pkt packet) memcpy(new_pkt.payload, message.data, 20); ComputeChecksum(&new_pkt); - + printf("[%.1f] A: send packet [%d] base [%d]\n", currenttime_(), nextseqnum, base); tolayer3(A, new_pkt); packet_sent++; // update packet sent counter - + winbuf[winrear] = new_pkt; winbuf[winrear].acknum = 0; /* initializing */ winrear = (winrear + 1) % WINDOWSIZE; @@ -266,15 +266,15 @@ void A_input(struct pkt packet) void A_packet_time_rinterrupt(struct timer* pkt_timer) { packet_time_out++; - + /* find pkt from buffer */ int found = 0; for(int i=0; ipkt_seq && winbuf[(winfront+i)%WINDOWSIZE].acknum == 0) { - + printf("[%.1f] A: packet [%d] time_ out, resend packet\n", currenttime_(), pkt_timer->pkt_seq); - - + + tolayer3(A, winbuf[(winfront+i)%WINDOWSIZE]); packet_sent++; // add this line packet_resent++; @@ -282,7 +282,7 @@ void A_packet_time_rinterrupt(struct timer* pkt_timer) break; } } - + if(found) { starttime_r(pkt_timer, A, RTT); } @@ -294,7 +294,7 @@ void B_input(struct pkt packet) static int expected_seq = 0; static struct pkt recv_window[8]; static int recv_marked[8] = {0}; /* 0: not marked, 1: marked */ - + if (CheckCorrupted(packet)) { if (packet.seqnum == 999999) { printf("[%.1f] B: packet [999999] corrupted\n", currenttime_()); @@ -304,35 +304,35 @@ void B_input(struct pkt packet) /* remoce packet_corrupt++,since checked in tolayer3 */ return; } - + /* 2. check */ if ((packet.seqnum >= expected_seq && packet.seqnum < expected_seq + WINDOWSIZE) || (packet.seqnum < expected_seq && packet.seqnum >= expected_seq - WINDOWSIZE)) { int slot = packet.seqnum % WINDOWSIZE; - + /* 3. buffer and sendACK */ if (recv_marked[slot] == 0 || recv_window[slot].seqnum != packet.seqnum) { /* buffer */ memcpy(&recv_window[slot], &packet, sizeof(struct pkt)); recv_marked[slot] = 1; - + /* send ack */ struct pkt ack_pkt; ack_pkt.acknum = packet.seqnum; ack_pkt.seqnum = NOTUSED; - memset(ack_pkt.payload, 0, 20); /* 清空ACK包的payload */ + memset(ack_pkt.payload, 0, 20); /* Clear ACK packet payload */ ComputeChecksum(&ack_pkt); tolayer3(B, ack_pkt); - + printf("[%.1f] B: packet [%d] received, send ACK [%d]\n", currenttime_(), packet.seqnum, packet.seqnum); } - - - while (recv_marked[expected_seq % WINDOWSIZE] == 1 && + + + while (recv_marked[expected_seq % WINDOWSIZE] == 1 && recv_window[expected_seq % WINDOWSIZE].seqnum == expected_seq) { tolayer5(B, recv_window[expected_seq % WINDOWSIZE].payload); - recv_marked[expected_seq % WINDOWSIZE] = 0; + recv_marked[expected_seq % WINDOWSIZE] = 0; packet_receieve++; expected_seq++; } @@ -344,7 +344,7 @@ void B_input(struct pkt packet) memset(ack_pkt.payload, 0, 20); ComputeChecksum(&ack_pkt); tolayer3(B, ack_pkt); - + printf("[%.1f] B: packet [%d] received, send ACK [%d]\n", currenttime_(), packet.seqnum, packet.seqnum); } @@ -381,13 +381,13 @@ void print_info() { printf("***********************************************************************************************************\n"); printf(" Packet Transmission Summary \n"); printf("***********************************************************************************************************\n"); - - /* 统计计算 - 每个包32KB,转换为Kb/s */ + + /* Statistics calculation - each packet is 32KB, convert to Kb/s */ float throughput = (packet_receieve * 32.0 * 8) / currenttime_(); - + /* 正确传输的包数量应该等于总消息数量,即接收方接收到的包数量 */ packet_correct = packet_receieve; - + printf("From Sender to Receiver: \n"); printf(" total sent pkts: %d \n", packet_sent); printf(" total correct pkts: %d \n", packet_correct); @@ -549,19 +549,19 @@ void init() /* initialize the simulator */ // float jimsrand(); printf("Enter the number of messages to simulate: \n"); - + scanf("%d", &nsimmax); total_sim_msg = nsimmax * 32; printf("Enter time_ between messages from sender's layer5 [ > 0.0]:\n"); scanf("%f", &lambda); printf("Enter channel pattern string\n"); - + scanf("%s", pattern); npttns = strlen(pattern); printf("Enter sender's window size\n"); - + scanf("%d", &WINDOWSIZE); winbuf = (struct pkt *) malloc(sizeof(struct pkt) * WINDOWSIZE);