(function(root){
'use strict';
const modes={
direct:{title:'PC끼리 직접 연결',route:'클라이언트 ↔ 호스트',server:'목록·인증·접속 요청만 담당',transport:'종단 간 QUIC / UDP',condition:'집 호스트에 UDP 포트포워딩 또는 양쪽에서 검증된 직접 경로가 필요합니다.',ports:'TCP 443 → 홈서버의 연결 관리 · UDP 40010 → 집 호스트 PC(예시)',detail:'화면·소리·입력은 홈서버 프로세스를 통과하지 않습니다. 집 공유기를 지나는 것과 홈서버에서 중계하는 것은 다릅니다.'},
home:{title:'홈서버를 통해 중계',route:'클라이언트 ↔ 홈서버 relay ↔ 호스트',server:'연결 관리 + 암호문 패킷 중계',transport:'종단 간 QUIC + relay 어댑터',condition:'두 PC가 홈서버 relay의 UDP 포트에 도달할 수 있어야 합니다.',ports:'TCP 443 → 연결 관리 · UDP 40000 → 홈서버 relay(자체 프로토콜 예시)',detail:'relay는 캡처·인코딩·화면 해독을 하지 않도록 설계합니다. UDP가 완전히 차단된 클라이언트에는 이 UDP relay만으로 해결되지 않습니다.'},
vpn:{title:'개인 VPN부터 사용',route:'클라이언트 ↔ 홈서버 VPN ↔ 호스트',server:'연결 관리 + VPN 라우팅',transport:'WireGuard 터널 안의 앱 QUIC',condition:'외부 PC에 VPN 설정을 넣고, 집 호스트로 가는 route와 방화벽을 구성합니다.',ports:'UDP 51820 → VPN(예시) · 연결 관리 API와 앱 포트는 VPN 내부에 둘 수 있음',detail:'여기서는 홈서버를 허브로 쓰는 WireGuard 구성입니다. 자동 P2P 경로를 찾는 mesh VPN과는 회선 사용 구조가 다릅니다.'},
vps:{title:'외부 VPS에서 중계',route:'클라이언트 ↔ 외부 VPS relay ↔ 호스트',server:'홈서버는 연결 관리 · VPS는 중계',transport:'종단 간 QUIC + 외부 relay',condition:'집 밖 호스트도 많거나 홈서버 중계 경로가 느릴 때 검토합니다. 현재 조건에서 필수는 아닙니다.',ports:'TCP 443 → 홈서버 · UDP 40000 → VPS relay(예시)',detail:'VPS의 지역·전송량·회선이 새 제약이 됩니다. 홈서버 장애까지 대비하려면 연결 관리도 별도로 이전/복제해야 합니다.'}
};
function hostname(value){
const v=String(value).trim().toLowerCase();
if(v.length>240||!v.includes('.')||!v.split('.').every(s=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(s))||!/[a-z]/.test(v.split('.').at(-1)))return null;
return v;
}
function bounded(value,min,max){const n=Number(value);if(!Number.isFinite(n)||n<min||n>max)throw new Error('계산 입력 범위를 확인하세요.');return n}
function estimate({mode,host,bitrate,sessions,upload,hours}){
if(!modes[mode]||!['home','away'].includes(host))throw new Error('경로를 선택하세요.');
const b=bounded(bitrate,5,100),n=bounded(sessions,1,5),u=bounded(upload,10,1000),h=bounded(hours,.5,8);
if(!Number.isInteger(n))throw new Error('세션 수는 정수입니다.');
const r=b*n*1.1,viaHome=mode==='home'||mode==='vpn';
const homeUp=host==='home'||viaHome?r:0;
const homeDown=host==='away'&&viaHome?r:0;
const relayInOut=mode==='vps'?r*2:mode==='home'?r*2:0;
return {media:r,homeUp,homeDown,relayInOut,homeGB:(homeUp+homeDown)*.45*h,
vpsGB:mode==='vps'?r*.45*h:0,ratio:homeUp/u,budget:u*.7,overBudget:homeUp>u*.7};
}
const api={modes,hostname,estimate};
if(typeof module!=='undefined'&&module.exports)module.exports=api;
root.HomeArchitecture=api;
})(globalThis);
생성 코드·템플릿
homeserver-model.js
design/homeserver-model.js