Skip to content

candidate操作をmiddlewareとして提供する - #12

Merged
tutinoko2048 merged 4 commits into
mainfrom
feat/rewrite-candidate-middleware
Sep 26, 2026
Merged

tutinoko2048 merged 4 commits into
mainfrom
feat/rewrite-candidate-middleware

Conversation

@kaito02020424

@kaito02020424 kaito02020424 commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

概要

#10 に対応するmiddlewareを作成しました:

変更・実装

export interface CandidateAddress {
  ip: string;
  port: number;
}

export interface RewriteCandidateOptions {
  /**
   * The address advertised in place of every routable upstream candidate; a field left out keeps
   * the candidate's own value. A function receives the addresses of the answer's candidates. Omit
   * it to keep the routable candidates at their own address.
   */
  mapAddress?:
    | Partial<CandidateAddress>
    | ((addresses: CandidateAddress[], c: JoinContext) => Partial<CandidateAddress>);
  /**
   * What to send when no candidate survives. Defaults to `'original'`, which returns the answer
   * untouched, trading the address leak for a connection that can still complete.
   */
  fallback?: 'drop' | 'original';
  /**
   * Masks the related address, which exposes the upstream's own address. Defaults to `true`
   * (`0.0.0.0` or `::`, port 0); an object masks only the fields it gives.
   */
  maskRelatedAddress?: boolean | Partial<CandidateAddress>;
}
  • mapAddressにはサーバーの外から見たIP/Portを指定します。指定したキーに対応する値のみ書き換えます。
    • 一般的にはIPのみ書き換えることが多いはずです。
    • なにも指定しない場合, 書き換えません。(BDSの設定を信頼する)
  • fallbackは, サーバー -> クライアントのcandidateを削除した際に0件になった場合の動作を指定します。
    • original - upstreamの内容をそのまま流します。 drop - 0件になった編集済みofferを流します。
    • なにも指定しない場合はoriginal動作となります。
  • maskRelatedAddressは, candidate内のraadr/rportの書き換え候補を編集します。指定したキーに対応する値のみ書き換えます。
    • 何も指定しない場合は, candidateの外向きアドレス(mapAddressで指定されているもの)のIP familyに合わせて,0.0.0.0:0か[::]:0になります
    • maskRelatedAddress.portに正当なport-range外の値を設定できず(Minecraftクライアントで拒否), 設定した場合はRangeErrorとなります。

その他注意事項

これはiceCandidate.tsの削除を伴う 破壊的変更 を行います

@tutinoko2048 tutinoko2048 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tutinoko2048
tutinoko2048 merged commit b222e7c into main Sep 26, 2026
1 check failed
@tutinoko2048
tutinoko2048 deleted the feat/rewrite-candidate-middleware branch September 26, 2026 16:33
@tutinoko2048 tutinoko2048 linked an issue Sep 26, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rewriteCandidates middlewareを追加する

2 participants