How Asterisk determine connected "context"

I am using Asterisk 1.6

sip.conf
[general]
allowguest=yes
bindaddr=0.0.0.0
bindport=5060
externhost=sip.myhost.org
localnet=192.168.11.0/24
directmedia=no
alwaysauthreject=yes

[hosta]
type=peer
context=hosta
insecure=invite,port
host=hosta
nat=route

[hostb]
type=friend
context=hostb
host=hostb
port=5061
secret=mysecret
username=asterisk
fromuser=asterisk

when hostb establish a sip call to hosta@sip.myhost.org (no authentication call) I would expect this call will connect into context “hosta” in extensions.conf, but the result is that Asterisk reported caller attempt to access extension “hosta” in context “hostb” but of course there is no such extension defined in context “hostb”

Is that mean when calling host not match with “host=”, Asterisk will automatically connect caller to the matching context of “host=”? What if no “host=” match the calling host, e.g. the calling host is from hostc ?

If I am not mistaken, your are testing your setup, that you make a call from hosta to hostb that are on the same server. Did you try to do the test from your GSM or other phone that is not connected to Asterisk?

When a SIP packet comes in, Asterisk finds the matching peer on the basis of the SIP paket’s source IP address (it compares it with the host parameters that are defined in the peers). If it does not find an appropriate peer, it routes the call to context=default.