What is the class do the function "Handshaker::DoHandShake()"

13 views
Skip to first unread message

xia rui

unread,
Aug 12, 2019, 10:11:40 PM8/12/19
to grpc.io

Hello,everyone 
I am trying to trace the workflow of gRPC connection setup. 

I find that class `HandshakerManager` uses `HandshakeManager::CallNextHandshakerLocked` to start handshaking and run its callback.

In `HandshakeManager::CallNextHandshakerLocked`, there is a function call around line 178
```
auto handshaker = handshakers_[index_];
    if (GRPC_TRACE_FLAG_ENABLED(grpc_handshaker_trace)) {
      gpr_log(
          GPR_INFO,
          "handshake_manager %p: calling handshaker %s [%p] at index %" PRIuPTR,
          this, handshaker->name(), handshaker.get(), index_);
    }

    handshaker->DoHandshake(acceptor_, &call_next_handshaker_, &args_);
```

I think function `DoHandshake` actually do the handshaking. But I do not know where it is.

I guess it may be `HttpConnectHandshaker::DoHandshake`, and mark a `printf` there. However, the function in `HandshakeManager` does not call `HttpConnectHandshaker`.

So, where is the actual implementation of `DoHandshake`. 

Thank you for your time.

Best wishes,
Xia Rui

Yang Gao

unread,
Aug 12, 2019, 10:19:07 PM8/12/19
to xia rui, grpc.io
That is like a C++ virtual call and there would be a method on each handshaker. For example, the one you found is one of them.
Not every handshaker is registered/run for every channel. You can run your client with GRPC_TRACE=handshaker GRPC_VERBOSITY=DEBUG and check the output log to see what handshakers are used.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/63dd2e13-06a5-4a0e-a218-3ea8386aa565%40googlegroups.com.

xia rui

unread,
Aug 12, 2019, 10:56:11 PM8/12/19
to grpc.io
Thank you, I have checked GRPC_TRACE=handshake, I have found that it uses `http-connect`. And the class `HttpConnectHandshaker` has the name, `http_connect`.

class HttpConnectHandshaker : public Handshaker {
 public:
  HttpConnectHandshaker();
  void Shutdown(grpc_error* why) override;
  void DoHandshake(grpc_tcp_server_acceptor* acceptor,
                   grpc_closure* on_handshake_done,
                   HandshakerArgs* args) override;
  const char* name() const override { return "http_connect"; }

I made a mistake that I forgot to upload the locally changed `HttpConnectHandshaker.cc` to the server and missed the mark in the code. 
To unsubscribe from this group and stop receiving emails from it, send an email to grp...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages