@@ -42,11 +42,14 @@ char* Rep_info::new_reply(
4242 r->set_size (message_size);
4343 r->trim ();
4444 char * ret = r->contents () + sizeof (Reply_rep);
45- std::lock_guard<SpinLock> mguard (lock);
46- auto ret_insert = reps.insert ({Key{(size_t )pid, rid, n}, std::move (r)});
47- if (ret_insert.second )
4845 {
49- return ret;
46+ std::lock_guard<SpinLock> mguard (lock);
47+ auto ret_insert =
48+ reps.insert ({Key{static_cast <size_t >(pid), rid, n}, std::move (r)});
49+ if (ret_insert.second )
50+ {
51+ return ret;
52+ }
5053 }
5154
5255 return nullptr ;
@@ -59,22 +62,23 @@ int Rep_info::new_reply_size() const
5962
6063void Rep_info::end_reply (int pid, Request_id rid, Seqno n, int size)
6164{
62- std::lock_guard<SpinLock> mguard (lock);
63- auto it = reps.find ({(size_t )pid, rid, n});
64- if (it != reps.end ())
65+ Reply* r;
6566 {
67+ std::lock_guard<SpinLock> mguard (lock);
68+ auto it = reps.find ({static_cast <size_t >(pid), rid, n});
69+ if (it == reps.end ())
70+ {
71+ LOG_INFO_FMT (
72+ " Attempt to end reply not in this < {}, {}, {} >" , pid, rid, n);
73+ return ;
74+ }
6675 Reply* r = it->second .get ();
6776 Reply_rep& rr = r->rep ();
6877 rr.rid = rid;
6978 rr.reply_size = size;
70- rr.digest = Digest (r->contents () + sizeof (Reply_rep), size);
7179 int old_size = sizeof (Reply_rep) + rr.reply_size ;
7280 r->set_size (old_size + MAC_size);
73- return ;
7481 }
75-
76- LOG_INFO << " Attempt to end reply not in this < " << pid << " ," << rid << " ,"
77- << n << " >" << std::endl;
7882}
7983
8084Reply* Rep_info::reply (int pid, Request_id rid, Seqno n)
@@ -91,34 +95,40 @@ Reply* Rep_info::reply(int pid, Request_id rid, Seqno n)
9195
9296void Rep_info::send_reply (int pid, Request_id rid, Seqno n, View v, int id)
9397{
94- std::lock_guard<SpinLock> mguard (lock);
95- auto it = reps.find ({(size_t )pid, rid, n});
96- if (it != reps.end ())
98+ std::unique_ptr<Reply> r;
9799 {
98- Reply* r = it-> second . get ( );
99- Reply_rep& rr = r-> rep ( );
100+ std::lock_guard<SpinLock> mguard (lock );
101+ auto it = reps. find ({( size_t )pid, rid, n} );
100102
101- PBFT_ASSERT (rr.reply_size != -1 , " Invalid state" );
102- PBFT_ASSERT (rr.extra == 0 && rr.v == 0 && rr.replica == 0 , " Invalid state" );
103+ if (it == reps.end ())
104+ {
105+ LOG_INFO << " Attempt to send reply not in this < " << pid << " ," << rid
106+ << " ," << n << " >" << std::endl;
107+ return ;
108+ }
103109
104- int old_size = sizeof (Reply_rep) + rr.reply_size ;
110+ r = std::move (it->second );
111+ reps.erase (it);
112+ }
105113
106- rr.extra = 1 ;
107- rr.v = v;
108- rr.replica = id;
114+ Reply_rep& rr = r->rep ();
109115
110- r->auth_type = Auth_type::out;
111- r->auth_len = sizeof (Reply_rep);
112- r->auth_src_offset = 0 ;
113- r->auth_dst_offset = old_size;
116+ PBFT_ASSERT (rr.reply_size != -1 , " Invalid state" );
117+ PBFT_ASSERT (rr.extra == 0 && rr.v == 0 && rr.replica == 0 , " Invalid state" );
114118
115- pbft::GlobalState::get_node ().send (r, pid);
116- reps.erase (it);
117- return ;
118- }
119+ int old_size = sizeof (Reply_rep) + rr.reply_size ;
120+
121+ rr.extra = 1 ;
122+ rr.v = v;
123+ rr.replica = id;
124+
125+ r->auth_type = Auth_type::out;
126+ r->auth_len = sizeof (Reply_rep);
127+ r->auth_src_offset = 0 ;
128+ r->auth_dst_offset = old_size;
119129
120- LOG_INFO << " Attempt to send reply not in this < " << pid << " , " << rid
121- << " , " << n << " > " << std::endl ;
130+ pbft::GlobalState::get_node (). send (r. get (), pid);
131+ return ;
122132}
123133
124134void Rep_info::clear ()
@@ -133,7 +143,6 @@ void Rep_info::dump_state(std::ostream& os)
133143 for (auto & pair : reps)
134144 {
135145 os << " cid: " << pair.first .cid << " rid: " << pair.first .rid
136- << " seqno: " << pair.first .n
137- << " digest hash:" << pair.second ->digest ().hash () << std::endl;
146+ << " seqno: " << pair.first .n << std::endl;
138147 }
139148}
0 commit comments