code: func (ctl *HandshakeController) cleanHandshake(pubkeyid string, topic *Topic, in bool, out bool) int {
  	ctl.lock.Lock()
  	defer ctl.lock.Unlock()
  	var deletecount int
  	var deletes []string
  	now := time.Now()
  	handshake := ctl.handshakes[pubkeyid][*topic]
  	log.Debug("handshake clean", "pubkey", pubkeyid, "topic", topic)
  	if in {
  		for i, key := range handshake.inKeys {
  			if key.expiredAt.Before(now) || (key.expiredAt.IsZero() && key.limit <= key.count) {
  				log.Trace("handshake in clean remove", "symkeyid", *key.symKeyID)
  				deletes = append(deletes, *key.symKeyID)
  				handshake.inKeys[deletecount] = handshake.inKeys[i]
  				deletecount++
  			}
  		}
  		handshake.inKeys = handshake.inKeys[:len(handshake.inKeys)-deletecount]
  	}
  	if out {
  		deletecount = 0
  		for i, key := range handshake.outKeys {
  			if key.expiredAt.Before(now) && (key.expiredAt.IsZero() && key.limit <= key.count) {
  				log.Trace("handshake out clean remove", "symkeyid", *key.symKeyID)
  				deletes = append(deletes, *key.symKeyID)
  				handshake.outKeys[deletecount] = handshake.outKeys[i]
  				deletecount++
  			}
  		}
  		handshake.outKeys = handshake.outKeys[:len(handshake.outKeys)-deletecount]
  	}
  	for _, keyid := range deletes {
  		delete(ctl.symKeyIndex, keyid)
  		ctl.pss.symKeyPool[keyid][*topic].protected = false
  	}
  	return len(deletes)
  }
docs: // Checks all symmetric keys in given direction(s) by
  // specified peer (public key) and topic for expiry.
  // Expired means:
  // - expiry timestamp is set, and grace period is exceeded
  // - message validity limit is reached