  Regenerating code is a class of code very suitable for distributed storage
systems, which can maintain optimal bandwidth and storage space. Two types of
important regenerating code have been constructed: the minimum storage
regeneration (MSR) code and the minimum bandwidth regeneration (MBR) code.
However, in hostile networks where adversaries can compromise storage nodes,
the storage capacity of the network can be significantly affected. In this
paper, we propose two optimal constructions of regenerating codes through
rate-matching that can combat against this kind of adversaries in hostile
networks: 2-layer rate-matched regenerating code and $m$-layer rate-matched
regenerating code. For the 2-layer code, we can achieve the optimal storage
efficiency for given system requirements. Our comprehensive analysis shows that
our code can detect and correct malicious nodes with higher storage efficiency
compared to the universally resilient regenerating code which is a
straightforward extension of regenerating code with error detection and
correction capability. Then we propose the $m$-layer code by extending the
2-layer code and achieve the optimal error correction efficiency by matching
the code rate of each layer's regenerating code. We also demonstrate that the
optimized parameter can achieve the maximum storage capacity under the same
constraint. Compared to the universally resilient regenerating code, our code
can achieve much higher error correction efficiency.
