Giter Site home page Giter Site logo

框架现在支不支持创建多个tcp tls客户端任务,每个tls客户端使用的证书私钥以及ca证书都不同的通信方式 about workflow HOT 26 CLOSED

coderwxl avatar coderwxl commented on June 3, 2024
框架现在支不支持创建多个tcp tls客户端任务,每个tls客户端使用的证书私钥以及ca证书都不同的通信方式

from workflow.

Comments (26)

Barenboim avatar Barenboim commented on June 3, 2024

这个问题你之前好像发过issue,当时我们没有解决。

我觉得这个功能还是有必要支持一下的。我跟进一下。

你多个client task是访问不同的协议(http/mysql这些),还是相同的协议呢?

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

相同的协议,目前用的是tcpsocket+tls,支持这个功能后麻烦给我说下。

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

大佬,改完了吗

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

还没有。我尽量今晚出一个可用的版本。你到时候可以先从我的fork拉。

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

可能又要改设计了,没那么快可以完工。

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

新的PR:#1530

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

我测试了下有问题。我开了30个线程,线程里面会定时创建临时tls客户端任务给服务端发请求,只有第一轮请求的15个客户端收到了响应数据,其它的没有收到响应数据(append函数没走进去),接下来所有线程就彻底都收不到服务端的响应了。

另外请问下SSL_CTX*需要我在外面手动释放还是框架会自动释放。

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

我们期待是在task生命周期之内,用户确保SSL_CTX有效。

正确性问题我们再测一下。

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

先合并到主项目的ssl_ctx分支了。具体用法,你参考一下WFMySQLConnection里这个:

void set_ssl_ctx(WFMySQLTask *task)

你把你的网络任务强传成WFComplexClientTask<MyRequest, MyResponse>类型,调用这个类的void set_ssl_ctx(SSL_CTX *)接口就可以了。ssl_ctx的生命周期需要覆盖task的生命周期。

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

我是这样创建的客户端任务:
WFCustomTask *task = WFNetworkTaskFactory<CustomRequest, CustomResponse>::create_client_task(m_isSSL ? TT_TCP_SSL : TT_TCP, (struct sockaddr *)&sockaddr, sizeof(sockaddr), ctx, 0, std::bind(&CTcpClient::process, this, _1));
这样也行吧

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

没事,我不着急,等你填上坑了我再用

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

你先试一下啊,现在也是可以用的。就是用这个函数:

static T *create_client_task(enum TransportType type,

我们也需要用户的使用建议才能确定怎么改。

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

我现在就是调用这个函数创建的任务,但是有我上面说的异常问题
static T *create_client_task(enum TransportType type,
const struct sockaddr *addr,
socklen_t addrlen,
SSL_CTX *ssl_ctx,
int retry_max,
std::function<void (T *)> callback);

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

我测试了下有问题。我开了30个线程,线程里面会定时创建临时tls客户端任务给服务端发请求,只有第一轮请求的15个客户端收到了响应数据,其它的没有收到响应数据(append函数没走进去),接下来所有线程就彻底都收不到服务端的响应了。

另外请问下SSL_CTX*需要我在外面手动释放还是框架会自动释放。

你是说这个问题吗?

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

是的。
用上面那个create_client_task创建任务后应该不需要再调用set_ssl_ctx来设置ctx吧

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

对,struct sockaddr + socklen 创建的,只能在create里设置,后面set_ssl_ctx无效。我看一下你说的问题。

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

@coderwxl 改了一点小问题,麻烦再试一下。觉得你说的现象有点奇怪,这边看不也会有这种问题。

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

我知道导致我上面说的异常原因了,是因为你这次改动没有使用连接池,导致每次都是新连接,但是服务端对连接数有限制,应该超过限制就会关闭新连接,从而导致后面就收不到服务端的响应了。

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

现在的代码还是没有复用连接吗?不应该啊。是不是你自定义协议没有调用set_keep_alive()?连接复用方面,和之前的没有什么区别。

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

不是我的问题,我只是调用不同的create_client_task函数,其它的没变:
image

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

你每次的ctx指针变了吗?不同的ctx(指针值),不会复用连接的。

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

可以了,我测了下没问题。

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

create_http_task能否也加上对ssl_ctx的支持

from workflow.

Barenboim avatar Barenboim commented on June 3, 2024

http的话,你可以模仿WFMySQLConnection的办法设置一下。可以自己搞个http client来创建任务,把ssl ctx封装进去。

如果加在我们的任务工厂里,那要加一堆函数。

from workflow.

coderwxl avatar coderwxl commented on June 3, 2024

好的,感谢大佬!

from workflow.

Related Issues (20)

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.