2626
2727namespace ppc ::protocol
2828{
29- class GrpcServerConfig
30- {
31- public:
32- using Ptr = std::shared_ptr<GrpcServerConfig>;
33- GrpcServerConfig () = default ;
34- GrpcServerConfig (EndPoint endPoint, bool enableHealthCheck)
35- : m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
36- {}
37- std::string listenEndPoint () const { return m_endPoint.listenEndPoint (); }
38-
39- void setEndPoint (EndPoint endPoint) { m_endPoint = endPoint; }
40- void setEnableHealthCheck (bool enableHealthCheck) { m_enableHealthCheck = enableHealthCheck; }
41-
42- EndPoint const & endPoint () const { return m_endPoint; }
43- EndPoint& mutableEndPoint () { return m_endPoint; }
44- bool enableHealthCheck () const { return m_enableHealthCheck; }
45-
46- protected:
47- ppc::protocol::EndPoint m_endPoint;
48- bool m_enableHealthCheck = true ;
49- };
5029class GrpcConfig
5130{
5231public:
@@ -71,10 +50,22 @@ class GrpcConfig
7150
7251 void setMaxSendMessageSize (uint64_t maxSendMessageSize)
7352 {
53+ if (maxSendMessageSize > c_maxMsgSize)
54+ {
55+ BOOST_THROW_EXCEPTION (
56+ WeDPRException () << bcos::errinfo_comment (
57+ " The MaxSendMessageSize limit is " + std::to_string (c_maxMsgSize)));
58+ }
7459 m_maxSendMessageSize = maxSendMessageSize;
7560 }
7661 void setMaxReceivedMessageSize (uint64_t maxReceivedMessageSize)
7762 {
63+ if (maxReceivedMessageSize > c_maxMsgSize)
64+ {
65+ BOOST_THROW_EXCEPTION (
66+ WeDPRException () << bcos::errinfo_comment (
67+ " The MaxReceivedMessageSize limit is " + std::to_string (c_maxMsgSize)));
68+ }
7869 m_maxReceivedMessageSize = maxReceivedMessageSize;
7970 }
8071
@@ -102,14 +93,53 @@ class GrpcConfig
10293 bool m_enableHealthCheck = true ;
10394 std::string m_loadBalancePolicy = " round_robin" ;
10495 bool m_enableDnslookup = false ;
96+ // Note: grpc use int to set the maxMsgSize
97+ uint64_t const c_maxMsgSize = INT_MAX;
10598
10699 // the max send message size in bytes
107- uint64_t m_maxSendMessageSize = 1024 * 1024 * 1024 ;
100+ uint64_t m_maxSendMessageSize = c_maxMsgSize ;
108101 // the max received message size in bytes
109- uint64_t m_maxReceivedMessageSize = 1024 * 1024 * 1024 ;
102+ uint64_t m_maxReceivedMessageSize = c_maxMsgSize ;
110103 int m_compressAlgorithm = 0 ;
111104};
112105
106+ class GrpcServerConfig : public GrpcConfig
107+ {
108+ public:
109+ using Ptr = std::shared_ptr<GrpcServerConfig>;
110+ GrpcServerConfig () = default ;
111+ GrpcServerConfig (EndPoint endPoint, bool enableHealthCheck)
112+ : m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
113+ {}
114+ ~GrpcServerConfig () override = default ;
115+
116+ std::string listenEndPoint () const { return m_endPoint.listenEndPoint (); }
117+
118+ void setEndPoint (EndPoint endPoint) { m_endPoint = endPoint; }
119+ void setEnableHealthCheck (bool enableHealthCheck) { m_enableHealthCheck = enableHealthCheck; }
120+
121+ EndPoint const & endPoint () const { return m_endPoint; }
122+ EndPoint& mutableEndPoint () { return m_endPoint; }
123+ bool enableHealthCheck () const { return m_enableHealthCheck; }
124+
125+ uint64_t maxMsgSize () const { return m_maxMsgSize; }
126+ void setMaxMsgSize (uint64_t maxMsgSize)
127+ {
128+ if (maxMsgSize > c_maxMsgSize)
129+ {
130+ BOOST_THROW_EXCEPTION (WeDPRException () << bcos::errinfo_comment (
131+ " The maxMsgSize limit is " + std::to_string (c_maxMsgSize)));
132+ }
133+ m_maxMsgSize = maxMsgSize;
134+ }
135+
136+ protected:
137+ ppc::protocol::EndPoint m_endPoint;
138+ bool m_enableHealthCheck = true ;
139+ uint64_t m_maxMsgSize = c_maxMsgSize;
140+ };
141+
142+
113143inline std::string printGrpcConfig (ppc::protocol::GrpcConfig::Ptr const & grpcConfig)
114144{
115145 if (!grpcConfig)
0 commit comments