You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

106 rivejä
3.5 KiB

  1. // +build !appengine
  2. /*
  3. *
  4. * Copyright 2018 gRPC authors.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. */
  19. package service
  20. import (
  21. "github.com/golang/protobuf/ptypes"
  22. channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
  23. "google.golang.org/grpc/internal/channelz"
  24. )
  25. func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOption {
  26. var opts []*channelzpb.SocketOption
  27. if skopts.Linger != nil {
  28. additional, err := ptypes.MarshalAny(&channelzpb.SocketOptionLinger{
  29. Active: skopts.Linger.Onoff != 0,
  30. Duration: convertToPtypesDuration(int64(skopts.Linger.Linger), 0),
  31. })
  32. if err == nil {
  33. opts = append(opts, &channelzpb.SocketOption{
  34. Name: "SO_LINGER",
  35. Additional: additional,
  36. })
  37. }
  38. }
  39. if skopts.RecvTimeout != nil {
  40. additional, err := ptypes.MarshalAny(&channelzpb.SocketOptionTimeout{
  41. Duration: convertToPtypesDuration(int64(skopts.RecvTimeout.Sec), int64(skopts.RecvTimeout.Usec)),
  42. })
  43. if err == nil {
  44. opts = append(opts, &channelzpb.SocketOption{
  45. Name: "SO_RCVTIMEO",
  46. Additional: additional,
  47. })
  48. }
  49. }
  50. if skopts.SendTimeout != nil {
  51. additional, err := ptypes.MarshalAny(&channelzpb.SocketOptionTimeout{
  52. Duration: convertToPtypesDuration(int64(skopts.SendTimeout.Sec), int64(skopts.SendTimeout.Usec)),
  53. })
  54. if err == nil {
  55. opts = append(opts, &channelzpb.SocketOption{
  56. Name: "SO_SNDTIMEO",
  57. Additional: additional,
  58. })
  59. }
  60. }
  61. if skopts.TCPInfo != nil {
  62. additional, err := ptypes.MarshalAny(&channelzpb.SocketOptionTcpInfo{
  63. TcpiState: uint32(skopts.TCPInfo.State),
  64. TcpiCaState: uint32(skopts.TCPInfo.Ca_state),
  65. TcpiRetransmits: uint32(skopts.TCPInfo.Retransmits),
  66. TcpiProbes: uint32(skopts.TCPInfo.Probes),
  67. TcpiBackoff: uint32(skopts.TCPInfo.Backoff),
  68. TcpiOptions: uint32(skopts.TCPInfo.Options),
  69. // https://golang.org/pkg/syscall/#TCPInfo
  70. // TCPInfo struct does not contain info about TcpiSndWscale and TcpiRcvWscale.
  71. TcpiRto: skopts.TCPInfo.Rto,
  72. TcpiAto: skopts.TCPInfo.Ato,
  73. TcpiSndMss: skopts.TCPInfo.Snd_mss,
  74. TcpiRcvMss: skopts.TCPInfo.Rcv_mss,
  75. TcpiUnacked: skopts.TCPInfo.Unacked,
  76. TcpiSacked: skopts.TCPInfo.Sacked,
  77. TcpiLost: skopts.TCPInfo.Lost,
  78. TcpiRetrans: skopts.TCPInfo.Retrans,
  79. TcpiFackets: skopts.TCPInfo.Fackets,
  80. TcpiLastDataSent: skopts.TCPInfo.Last_data_sent,
  81. TcpiLastAckSent: skopts.TCPInfo.Last_ack_sent,
  82. TcpiLastDataRecv: skopts.TCPInfo.Last_data_recv,
  83. TcpiLastAckRecv: skopts.TCPInfo.Last_ack_recv,
  84. TcpiPmtu: skopts.TCPInfo.Pmtu,
  85. TcpiRcvSsthresh: skopts.TCPInfo.Rcv_ssthresh,
  86. TcpiRtt: skopts.TCPInfo.Rtt,
  87. TcpiRttvar: skopts.TCPInfo.Rttvar,
  88. TcpiSndSsthresh: skopts.TCPInfo.Snd_ssthresh,
  89. TcpiSndCwnd: skopts.TCPInfo.Snd_cwnd,
  90. TcpiAdvmss: skopts.TCPInfo.Advmss,
  91. TcpiReordering: skopts.TCPInfo.Reordering,
  92. })
  93. if err == nil {
  94. opts = append(opts, &channelzpb.SocketOption{
  95. Name: "TCP_INFO",
  96. Additional: additional,
  97. })
  98. }
  99. }
  100. return opts
  101. }