Giter Site home page Giter Site logo

yyvpn's Introduction

YYVPN

环境

  • Xcode 11.6
  • iOS 13
  • MacOS 10.15

导航

1-总览

2-Client开发

3-Tunnel开发

4-Server开发

5-App和Extension通信

完整代码在此,熟悉的小伙伴可以直接试试。

前言

之前用NEKit框架写过一个自用的科学上网工具,后面还写过一个代理http/https的App,虽然都做出来了,但它们核心功能都是NEKit封装好了的,所以对Network Extension的理解还是微乎其微。

最近想再学习下网络这块,所以又看了些资料,也稍微深入的学习下Network Extension。

目标

一个iOS客户端App,一个MacOS服务器App,功能如下:

  1. 开启自己的App后,抓取手机所有的流量,发送到自己的代理服务器
  2. 代理服务器转发所有请求到真正的服务器
  3. 代理服务器收到响应后,再回传给App

最后实现效果如下:

Client:

Server:

先来看看,要实现上面流程需要用到哪些技术。

涉及技术

  • Network Extension
  • Swift UI,Combine
  • 多Target共享代码,相互通信
  • C语言Socket编程

客户端App使用Swift UI构建界面,使用Network Extension的NEPacketTunnelProvider抓取手机的IP数据包,通过UDP发送给服务器。

服务器App也使用Swift UI构建界面,使用C语言的Socket编程处理收到的数据。

流程如下图:

+-----+            +---------+              +-------+           +---------+
| App |            | Tunnel  |              | Proxy |           | Server  |
+-----+            +---------+              +-------+           +---------+
   |                    |                       |                    |
   | Real request       |                       |                    |
   |------------------->|                       |                    |
   |                    | ------------------\   |                    |
   |                    |-| ReadPackets(IP) |   |                    |
   |                    | |-----------------|   |                    |
   |                    |                       |                    |
   |                    | Packaging to UDP      |                    |
   |                    |---------------------->|                    |
   |                    |                       |                    |
   |                    |                       | Real request       |
   |                    |                       |------------------->|
   |                    |                       |                    |
   |                    |                       |      Real Response |
   |                    |                       |<-------------------|
   |                    |                       |                    |
   |                    |      Packaging to UDP |                    |
   |                    |<----------------------|                    |
   |   ---------------\ |                       |                    |
   |   | WritePackets |-|                       |                    |
   |   |--------------| |                       |                    |
   |                    |                       |                    |
   |      Real response |                       |                    |
   |<-------------------|                       |                    |
   |                    |                       |                    |

后面就来一步步讲解。

参考链接

yyvpn's People

Contributors

cgcym1234 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.